Phphttp request problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.