This article is mainly to share with you in PHP to get the request header and the response header, hope to help everyone.
1. Get the response header from Curl
$oCurl = Curl_init ();//Set the request header, sometimes need, sometimes do not, see if the request URL has corresponding requirements $header[] = "content-type:application/x-www-form-urlencoded" ; $user _agent = "mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/33.0.1750.146 safari/537.36"; c Url_setopt ($oCurl, Curlopt_url, $SURL) curl_setopt ($oCurl, Curlopt_httpheader, $header);//Return to Response_header, This option is very important, if not true, only gets the body of the response curl_setopt ($oCurl, Curlopt_header, true);//Whether the body of the response is not required, in order to save bandwidth and time, in case only need to respond to the header can not body curl _setopt ($oCurl, Curlopt_nobody, true);//Use the uacurl_setopt defined above ($oCurl, curlopt_useragent, $user _agent); curl_setopt ($ Ocurl, Curlopt_returntransfer, 1);//no POST request, meaning to curl_setopt ($oCurl, Curlopt_post, false) via GET request; $sContent = Curl _exec ($oCurl);//Get response result in: Head size $headersize = Curl_getinfo ($oCurl, curlinfo_header_size);//To Get header information content $header = substr ($sContent, 0, $headerSize); Curl_close ($oCurl);
2. Get the request header from Curl
$oCurl = Curl_init (); curl_setopt ($oCurl, Curlopt_url, "https:// 117.28.240.235:8002/ipcc/agent/login "); curl_setopt ($oCurl, Curlopt_httpheader, $header);//Turn off HTTPS authentication curl_setopt ($oCurl, Curlopt_ssl_verifypeer, false); curl_setopt ($oCurl, Curlopt_ssl_verifyhost, false);//Critical, curlinfo_header_out option to get the request header information curl_setopt ($oCurl, Curlinfo_header_out, TRUE); curl_setopt ($oCurl, Curlopt_returntransfer, 1); curl_setopt ($oCurl, Curlopt_post, 1); Curl _setopt ($oCurl, Curlopt_postfields, $bodystr), $sContent = Curl_exec ($oCurl);//Curl_getinfo () can get the information of the request header $a=curl_ GetInfo ($oCurl);