How PHP Curl sets custom request headers and print request header information

Source: Internet
Author: User

$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

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.