Home >Backend Development >PHP Tutorial >What should I do if a 403 error occurs in PHP Curl? curl error solution

What should I do if a 403 error occurs in PHP Curl? curl error solution

WBOY
WBOYOriginal
2016-07-25 08:53:172777browse
ECURL_SETOPT ($ this-& gt; msh, curlopt_httpproxytunnel, true); There is no detailed explanation in the HP document, However, there is a detailed explanation in man curl. Both are proxies. proxytunnel (-p parameter) allows other protocols to be transmitted through the http proxy, while proxy (-x parameter) can only use the http protocol. So I guess that Google Baidu's server is at odds with curl's proxytunnel, so 403 is returned. After disabling the first sentence of the above two lines of code, curl access returns to normal.
In addition, it is different under several operating systems. On a MAC OSX, proxytunnel must be explicitly disabled. Curl version:
$ curl --versioncurl 7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3Protocols: tftp ftp telnet dict ldap http file https ftps
Features: GSS-Negotiate IPv6 Largefile NTLM SSL libz

Copy code

The other ubuntu is not affected at all and can be used no matter what, curl version:
  1. $ curl --version
curl 7.18.2 (i486-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.10
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

Copy code

centos on the MT host is fine too, curl version:
  1. $ curl --version
curl 7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Protocols: tftp ftp telnet dict ldap http file https ftps Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

Copy code

It seems that it is not entirely a curl version problem, MAC OSX is indeed different. There is another reason why curl will return a 403 error, if it is set:
  1. curl_setopt($ch, CURLOPT_NOBODY, true);
Copy the code

and 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 may be due to this reason.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn