Phphttp request error message: {"errcode": 41001, "errmsg": "access_token missing "}
// Send a POST request
$ Url = "https://api.weixin.qq.com/cgi-bin/qrcode/create? Access_token = ";
$ Access_token = "bz6LKNCiQN5fHDZNJwWbCiPXqRkrlkBUcBGwb3MlM-tmnXK6TGsHGbsETwcOXmezlIouHdD7Rv3g9aLicuF-gA ";
$ Url = $ url. urlencode ($ access_token );
Echo "request url:". $ url ."
";
// Request content
$ Data ['action _ name'] = "QR_LIMIT_SCENE ";
$ Scene ['scene _ id'] = 10;
$ Action_info ['scene '] = $ scene;
$ Data ['action _ info'] = $ action_info;
$ Data = json_encode ($ data );
Echo "request parameter:". $ data ."
";
// Url
$ Url_info = parse_url ($ url );
Var_dump ($ url_info );
Echo"
";
If (! Isset ($ url_info ['port'])
{
$ Url_info ['port'] = 80;
// Simulate the http request header
$ 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); // send HTTP hair
$ Inheader = 1;
While (! Feof ($ fp ))
{
// $ Result is the data returned after submission.
$ Result. = fgets ($ fp, 1024 );
}
Echo $ result;
Fclose ($ fp );
?>
Reply to discussion (solution)
41001 the access_token parameter is missing
Return code description
The access_token parameter is included in my url. this is what will happen above.
$ Fp = fsockopen ($ url_info ["host"], $ url_info ["port"]);
And
$ 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 ";
No token is found.
Access_token is included in the url and the get parameter. how should I add this parameter?
$ Request. = "POST". $ url_info ['path']. "HTTP/1.1 \ n ";
Enter the name of the target page with path and parameters, for example
/Cgi-bin/qrcode/create? Access_token = ?????
Both get and post methods are written in this way.
You can splice the parameter token behind the path.