Curl solves infinite redirects

Source: Internet
Author: User
RT, some Web servers are configured 404Rule: Redirect to the current Web site 相对URLThat, in this case, may produce 无限重定向The problem, then, in the use of CURLWhat should I do to solve this problem when I get the data?

Reply content:

RT, some Web server configured the 404 rule: Redirect to the current site 相对URL , in this case, may produce 无限重定向 problems, then, when using the CURL fetch data, how should the problem be solved?

1 if multiple redirects are required, set curl following (Curlopt_followlocation)
2 If multiple redirects are not received, set the maximum number of redirect
3 If you need to analyze yourself, then resolve the HTTP response yourself, making a decision

Do you want to limit the number of redirects or?
CURLOPT_MAXREDIRSThe parameter can limit//Specify the maximum number of HTTP redirects, which is used with curlopt_followlocation.
Document Address: http://php.net/manual/zh/function.curl-setopt.php

curl_setopt($ch, CURLOPT_MAXREDIRS, 5);//最多重定向5次

Curl can automatically follow the 301, see https://github.com/leaps/httpclient/blob/master/src/Leaps/HttpClient/Adapter/Curl.php
314 lines have the relevant 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.