php http请求有关问题
程序员文章站
2022-04-08 13:46:51
...
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 方式,都是这样写
错误信息:{"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 方式,都是这样写
相关文章
相关视频
上一篇: PHP中类似Jsp的out.print的函数,该如何解决
下一篇: Hibernate事务属性