最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php http请求有关问题

来源:http://erdangjiade.com/topic/79816.html 你好,世界。 2017-10-04 21:03浏览(0)

php http请求问题
错误信息:{"errcode":41001,"errmsg":"access_token missing"}
<?php
//发送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 ."<br>";
//要请求的内容
$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 ."<br>";

//url
$url_info = parse_url($url);
var_dump($url_info);
echo "<br>";
if(!isset($url_info['port']))
{
$url_info['port'] = 80;
//模拟http请求头
$request .= "POST ".$url_info['path']." HTTP/1.1n";
$request .= "Host: ".$url_info['host']."n";
$request .= "Content-type: application/x-www-form-urlencodedn";
$request .= "Content-length: ".strlen($data)."n";
$request .= "Connection: closen";
$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.1n";
$request .= "Host: ".$url_info['host']."n";
$request .= "Content-type: application/x-www-form-urlencodedn";
$request .= "Content-length: ".strlen($data)."n";
$request .= "Connection: closen";
$request .= "n";
$request .= $data."n";
里没有发现有token的信息。

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

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2