PHP curl: capture the page after 302 redirection

Source: Internet
Author: User

Php curl captures the page as follows:

$ Url = 'HTTP: // www.baidu.com '; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_VERBOSE, true ); curl_setopt ($ ch, CURLOPT_HEADER, true); curl_setopt ($ ch, CURLOPT_NOBODY, true); curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get'); curl_setopt ($ ch, expires, true); curl_setopt ($ ch, CURLOPT_TIMEOUT, 20); curl_setopt ($ ch, CURLOPT_AUTOREFERER, true); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true ); $ ret = curl_exec ($ ch); $ info = curl_getinfo ($ ch); curl_close ($ ch );


If you capture the status 302, some redirects need to pass parameters to the next link during the re-capturing process, the next link also sets illegal access if the corresponding parameter is not received.

Curl_setopt ($ curl, CURLOPT_CUSTOMREQUEST, 'get ');

The display should be normal.

The above is used to capture the function, and it should be almost no problem. You can check the information about CURLOPT_CUSTOMREQUEST.

Use a custom request information instead of "GET" or "HEAD" as an HTTP request. This is applicable to the execution of "DELETE" or other more concealed HTTP requests. Valid values include "GET", "POST", and "CONNECT. That is to say, do not enter the entire HTTP request here. For example, inputting "GET/index.html HTTP/1.0 \ r \ n" is incorrect.

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.