Example
| The code is as follows |
Copy Code |
|
$data = ' {' type ': ' News ', ' offset ': $, ' count ': 20} ';
$access _token = "0ERCBG (112 words omitted) DZROR0PJBFLHAHAMQW";
$url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=". $access _token;
Send data
$ch = Curl_init ();
$timeout = 300;
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_referer, "http://www.111cn.net/"); The disguise of the antecedents
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_postfields, $data);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE); Add this line when the URL is SSL to resolve page whitespace
$rs = curl_exec ($ch);
Curl_close ($ch);
Output
$rs = Json_decode ($RS);
Echo ' <pre> ';
Print_r ($RS);
Echo ' </pre> '; |
Example
Method 1 feel also very clumsy, it seems difficult to meet my needs, and finally forget on which English website found the following method:
| The code is as follows |
Copy Code |
function Do_post_request ($url, $data, $optional _headers = null)
{
$params = Array (' http ' => array (
' Method ' => ' POST ',
' Content ' => $data
));
if ($optional _headers!== null) {
$params [' http '] [' header '] = $optional _headers;
}
$ctx = Stream_context_create ($params);
$fp = @fopen ($url, ' RB ', false, $ctx);
if (! $fp) {
throw new Exception ("Problem with $url, $php _errormsg");
}
$response = @stream_get_contents ($FP);
if ($response = = False) {
throw new Exception ("Problem reading data from $url, $php _errormsg");
}
return $response;
} |
Try it, the feeling is very good, concise, universal, and return content is only the body content