PHP curl obtains the response status instance.

Source: Internet
Author: User

PHP curl can simulate an http request from the server, such as web page capture and simulated login. According to the option settings, you can get the response header and body in the returned result of curl_exec, but is there no response status. To obtain the status, you must run curl_exec and then use curl_getinfo.

For example:

The Code is as follows: Copy code

$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, 'HTTP: // www. bKjia. c0m ');
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 200 );
Curl_setopt ($ ch, CURLOPT_HEADER, FALSE );
Curl_setopt ($ ch, CURLOPT_NOBODY, FALSE );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, FALSE );
Curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get ');

Curl_exec ($ ch );

$ HttpCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE );

In addition, curl_getinfo can obtain many other 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.