Home > Backend Development > PHP Tutorial > php http请求有关问题

php http请求有关问题

WBOY
Release: 2016-06-13 12:05:29
Original
1208 people have browsed it

php http请求问题
错误信息:{"errcode":41001,"errmsg":"access_token missing"}
//发送POST请求
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=";
$access_token = "bz6LKNCiQN5fHDZNJwWbCiPXqRkrlkBUcBGwb3MlM-tmnXK6TGsHGbsETwcOXmezlIouHdD7Rv3g9aLicuF-gA";
$url = $url . urlencode($access_token);
echo "请求url:" . $url ."
";
//要请求的内容
$data['action_name'] = "QR_LIMIT_SCENE";
$scene['scene_id'] = 10;
$action_info['scene'] = $scene;
$data['action_info'] = $action_info;
$data = json_encode($data);
echo "请求参数:" . $data ."
";

//url
$url_info = parse_url($url);
var_dump($url_info);
echo "
"; 
if(!isset($url_info['port']))
{
    $url_info['port']    =    80;
    //模拟http请求头
    $request    .=    "POST ".$url_info['path']." HTTP/1.1\n";
    $request    .=    "Host: ".$url_info['host']."\n";
    $request    .=    "Content-type: application/x-www-form-urlencoded\n";
    $request    .=    "Content-length: ".strlen($data)."\n";
    $request    .=    "Connection: close\n";
    $request    .=    "\n";
    $request    .=    $data."\n";
}

$fp = fsockopen($url_info["host"], $url_info["port"]);
fputs($fp, $request);//把HTTP头发送出去

$inheader = 1;
while(!feof($fp)) 
{
    //$result 是提交后返回的数据
    $result .= fgets($fp, 1024);
}
echo $result;
fclose($fp);
?>
------解决方案--------------------
41001  缺少access_token参数

返回码说明
------解决方案--------------------
$fp = fsockopen($url_info["host"], $url_info["port"]);

 $request    .=    "POST ".$url_info['path']." HTTP/1.1\n";
    $request    .=    "Host: ".$url_info['host']."\n";
    $request    .=    "Content-type: application/x-www-form-urlencoded\n";
    $request    .=    "Content-length: ".strlen($data)."\n";
    $request    .=    "Connection: close\n";
    $request    .=    "\n";
    $request    .=    $data."\n";
里没有发现有token的信息。

------解决方案--------------------
$request    .=    "POST ".$url_info['path']." HTTP/1.1\n";
这里填写带路径和参数的目标页名称,比如
/cgi-bin/qrcode/create?access_token=?????
无论是 get 还是 post 方式,都是这样写

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template