This article mainly introduces how php uses curl to access the domain name and returns the 405methodnotallowed prompt. For more information, see
This article mainly introduces how php uses curl to access a Domain Name and returns the 405 method not allowed prompt. If you need a friend, refer
/*** Http test * Note: PHP versions later than 5.2 support CURL_IPRESOLVE_V4 * @ param $ url website domain name * @ param $ type Website access protocol * @ param $ ipresolve Resolution Method */public function web_http ($ url, $ type, $ ipresolve) {// set the Header $ header [] = "Accept: application/json"; $ header [] = "Accept-Encoding: gzip "; $ httptype = function_exists ('curl _ init '); if (! $ Httptype) {$ html = file_get_contents ($ url);} else {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url ); // output header information curl_setopt ($ ch, CURLOPT_HEADER, 1); // recursive access to the location jump link until 200OKcurl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1) is returned ); // do not output curl_setopt ($ ch, CURLOPT_NOBODY, 1) for the BODY part in HTML; // return the result as a file stream instead of directly outputting curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // access if ($ ipresolve = 'ipv6 ') {curl_setopt ($ ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6) in IPv4/IPv6 mode );} else {curl_setopt ($ ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);} // Add an HTTP header to request curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header) through compression and GET ); curl_setopt ($ ch, CURLOPT_ENCODING, "gzip"); curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get'); // clear the DNS Cache curl_setopt ($ ch, expires, 0 ); // set the connection timeout value curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 15); // set the access timeout value curl_setopt ($ ch, CURLOPT_TIMEOUT, 50); // set the User-agentcurl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/Listen 0.1132.47 Safari/1234'); if ($ type = "https ") {// do not check the certificate source curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); // check from the certificate whether the SSL encryption algorithm has curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, true);} // perform the Curl operation $ html = curl_exec ($ ch); // obtain the information of a cURL connection resource handle (obtain the information about the last transfer) $ info = curl_getinfo ($ ch); curl_close ($ ch);} return $ info ;}
The above is a basic curl access method. Because IPv6 needs to be used here, the corresponding options are added. I believe you can understand it, the frequently used options appear above, and you can choose between them as needed.
Status Code 405/Method Not Allowed indicates that the request Method is Not supported. This error is Not common.
This error occurs because curl uses the post method to submit access by default, and the post method has no permission under such domain names. For example, this type of problem occurs during testing, after the get method is modified and the header is added, the access can be normal. I guess that Amazon basically uses the get method, is regarded as a human click, and the post is blocked accordingly.
The following code is added:
// Set the Header $ header [] = "Accept: application/json"; $ header [] = "Accept-Encoding: gzip "; // Add an HTTP header to request curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header) using compression and GET; curl_setopt ($ ch, CURLOPT_ENCODING, "gzip"); curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get ');
The command line format is:
Curl-v