用file_get_contents()发送POST请求

178次阅读
没有评论
function post_file_get_content($url){$data = array( 'url'=>$url);

$query = json_encode($data); // 要携带的参数 根据实际情况 有时需要用 http_build_query() 转换

$options['http'] = array(
 'timeout'=>60,
 'method' => 'POST',
 'header' => 'Content-type:application/x-www-form-urlencoded',
 'content' => $query
 );

 $url = "http://dwz.cn/admin/create";
 $context = stream_context_create($options);

 $result = file_get_contents($url, false, $context);

 $baidu_dwz = json_decode($result,true);

 if($baidu_dwz['Code']===0){return json_encode(['status'=>1,'url_short'=>$baidu_dwz ['ShortUrl']]);
 }else{return json_encode(['status'=>0,'error_code'=>$baidu_dwz ['ErrMsg']]);
 }

 }
正文完
有偿技术支持加微信
post-qrcode
 
评论(没有评论)
验证码