Php post data upload instance based on CURL, phpcurlpost instance
This example describes how PHP uploads POST Data Based on CURL. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows:
/// QR code
$ QRCode_URL = "https://api.weixin.qq.com/cgi-bin/qrcode/create? Access_token = ". $ ACC_TOKEN;
$ Data = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123 }}}';
/*
$ Ch = curl_init ($ MENU_URL );
Curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, "POST ");
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ('content-Type: application/json', 'content-Length: '. strlen ($ data )));
$ Info = curl_exec ($ ch );
*/
Function post ($ url, $ params = false, $ header = array ()){
$ Ch = curl_init ();
$ CookieFile = 'sdadsd_cookiejar.txt ';
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 60 );
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookieFile );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookieFile );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE );
Curl_setopt ($ ch, CURLOPT_HTTPGET, true );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 30 );
If ($ params! = False) {curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ params );}
Curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (Windows NT 5.1; rv: 21.0) Gecko/20100101 Firefox/123456 ');
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
$ Result = curl_exec ($ ch );
Curl_close ($ ch );
Return $ result;
}
$ Result = post ($ QRCode_URL, $ data );
I hope this article will help you with PHP programming.