CURL solves infinite redirection

Source: Internet
Author: User
RT: some website servers are configured with the 404 rule: redirect to the relative URL of the current website. In this case, infinite redirection may occur. When you use CURL to obtain data, how should we solve this problem? RT, some website servers are configured 404Rule: redirect to the current website Relative URLIn this case Unlimited redirectionIn use CURLHow can I solve this problem when obtaining data?

Reply content:

RT, some website servers are configured404Rule: redirect to the current websiteRelative URLIn this caseUnlimited redirectionIn useCURLHow can I solve this problem when obtaining data?

1 If multiple redirection is required, set the curl to follow (CURLOPT_FOLLOWLOCATION)
2. If multiple redirection attempts are unacceptable, set the maximum number of redirect requests.
3. If you need to analyze the http response by yourself, make a decision.

Do you want to limit the number of redirection times?
CURLOPT_MAXREDIRSThe parameter can limit the maximum number of HTTP redirects. This option is used with CURLOPT_FOLLOWLOCATION ..
Document address: http://php.net/manual/zh/function.curl-setopt.php

Curl_setopt ($ ch, CURLOPT_MAXREDIRS, 5); // redirect up to 5 times

CURL can automatically follow 301, see https://github.com/leaps/httpclient/blob/master/src/Leaps/HttpClient/Adapter/Curl.php
The first line contains related code.

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.