$header = [ ' Client:h5 ', ' token:test ',];curlrequest ($url$params true$header);
PHP 5.1.3 Support using Curl_getinfo function to obtain the request header
The specific need to set curl_setopt ($ch, Curlinfo_header_out, true);
Then use Curl_getinfo ($ch, curlinfo_header_out) after the request occurs;
functionCurlrequest ($url,$params=Array(),$is _post=false,$time _out= 10,$header=Array()) { $str _cookie=isset($ext _params[' Str_cookie ']) ?$ext _params[' Str_cookie ']: ';$ch= Curl_init ();//Initialize Curlcurl_setopt ($ch, Curlopt_url,$url);//crawl specified Web pagecurl_setopt ($ch, Curlopt_header, 0);//sets whether to return response headercurl_setopt ($ch, Curlopt_returntransfer, 1);//This option needs to be set to true if the result is a string and output to the screen//when you need to get the header information from the Curl_getinfo to make the request.curl_setopt ($ch, Curlinfo_header_out,true); curl_setopt ($ch, Curlopt_timeout,$time _out); curl_setopt ($ch, Curlopt_connecttimeout,$time _out); curl_setopt ($ch, Curlopt_post,$is _post); if($is _post) {curl_setopt ($ch, Curlopt_postfields,$params); } if($str _cookie) {curl_setopt ($ch, Curlopt_cookie,$str _cookie); } if($header) {curl_setopt ($ch, Curlopt_httpheader,$header); } $response= Curl_exec ($ch);
Print the header information for the request$request _header = Curl_getinfo ($ch, curlinfo_header_out); Print_r ($request _header);Curl_close ($ch); return $response; }
How PHP Curl sets custom request headers and print request header information