What about PHP Curl 403 error? How to fix curl errors

Source: Internet
Author: User
Tags idn ldap
    1. curl_setopt ($this->msh, Curlopt_httpproxytunnel, true);
    2. curl_setopt ($this->msh, Curlopt_proxy, $phost);
Copy Code

There is no detail in the PHP documentation, but there is a detailed explanation in man curl, both proxies, and the Proxytunnel (-p parameter) allows other protocols to be transmitted over HTTP proxies, while the proxy (-x parameter) can only go through the HTTP protocol. So I guess, Google Baidu's server and Curl Proxytunnel, so return 403. After disabling the first sentence of the above 2 lines of code, curl access is back to normal.

In addition, several operating systems are not the same, a Mac OSX will be explicitly disabled Proxytunnel, curl version:

    1. $ Curl--version
    2. Curl 7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 openssl/0.9.7l zlib/1.2.3
    3. Protocols:tftp ftp telnet dict ldap http file https FTPs
    4. Features:gss-negotiate IPv6 largefile NTLM SSL libz
Copy Code

And another Ubuntu is completely unaffected, how can be used, curl version:

    1. $ Curl--version
    2. Curl 7.18.2 (I486-PC-LINUX-GNU) libcurl/7.18.2 openssl/0.9.8g zlib/1.2.3.3 libidn/1.10
    3. Protocols:tftp ftp telnet dict ldap ldaps http file https FTPs
    4. Features:gss-negotiate IDN IPv6 largefile NTLM SSL libz
Copy Code

CentOS on Mt host is OK, curl version:

    1. $ Curl--version
    2. Curl 7.15.5 (I686-REDHAT-LINUX-GNU) libcurl/7.15.5 openssl/0.9.8b zlib/1.2.3 libidn/0.6.5
    3. Protocols:tftp ftp telnet dict ldap http file https FTPs
    4. Features:gss-negotiate IDN IPv6 largefile NTLM SSL libz
Copy Code

It doesn't seem to be a completely curl version, MAC OSX is a really different thing. There is also a reason why curl returns a 403 error if it is set:

    1. curl_setopt ($ch, Curlopt_nobody, true);
Copy Code

You need to follow the settings:

    1. curl_setopt ($ch, Curlopt_customrequest, ' GET ');
Copy Code

Otherwise, a 403 error will be returned because the HTTP server does not allow the HEAD command.

Reference: Trouble with a CURL request in PHP (http://forums.devshed.com/php-development-5/ trouble-with-a-curl-request-in-php-445222.html). The reason why curl on MAC OSX is special is not ruled out.

  • Related Article

    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.