php http请求问题

WBOY
Release: 2016-06-23 13:50:51
Original
1161 people have browsed it

错误信息:{"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参数

返回码说明

我的url里面带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的信息。

access_token在url里面,get参数,这个参数应该怎么加

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

把参数token拼接在path后面的确可以了

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!