<p>使用PHP curl获取页面内容或提交数据,有时候希望返回的内容作为变量储存,而不是直接输出。一般curl爬取过程中,会返回一个http_code,通过这个状态我们就可以知道请求的结果,今天测试curl爬取远程图片的时候出现状态码为400的错误,报错内容为”invalid User-Agent header“<span style="color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">①</span>,后来就找了一些有关”http_code状态码“的资料,给大家参考下:</p><p>下面是他们的意义信息<br/></p><p>$http_code["0"] = "Unable to access";</p><p>$http_code["100"] = "Continue";</p><p>$http_code["101"] = "Switching Protocols";</p><p>$http_code["200"] = "OK";</p><p>$http_code["201"] = "Created";</p><p>$http_code["202"] = "Accepted";</p><p>$http_code["203"] = "Non-Authoritative Information";</p><p>$http_code["204"] = "No Content";</p><p>$http_code["205"] = "Reset Content";</p><p>$http_code["206"] = "Partial Content";</p><p>$http_code["300"] = "Multiple Choices";</p><p>$http_code["301"] = "Moved Permanently";</p><p>$http_code["302"] = "Found";</p><p>$http_code["303"] = "See Other";</p><p>$http_code["304"] = "Not Modified";</p><p>$http_code["305"] = "Use Proxy";</p><p>$http_code["306"] = "(Unused)";</p><p>$http_code["307"] = "Temporary Redirect";</p><p>$http_code["400"] = "Bad Request";</p><p>$http_code["401"] = "Unauthorized";</p><p>$http_code["402"] = "Payment Required";</p><p>$http_code["403"] = "Forbidden";</p><p>$http_code["404"] = "Not Found";</p><p>$http_code["405"] = "Method Not Allowed";</p><p>$http_code["406"] = "Not Acceptable";</p><p>$http_code["407"] = "Proxy Authentication Required";</p><p>$http_code["408"] = "Request Timeout";</p><p>$http_code["409"] = "Conflict";</p><p>$http_code["410"] = "Gone";</p><p>$http_code["411"] = "Length Required";</p><p>$http_code["412"] = "Precondition Failed";</p><p>$http_code["413"] = "Request Entity Too Large";</p><p>$http_code["414"] = "Request-URI Too Long";</p><p>$http_code["415"] = "Unsupported Media Type";</p><p>$http_code["416"] = "Requested Range Not Satisfiable";</p><p>$http_code["417"] = "Expectation Failed";</p><p>$http_code["500"] = "Internal Server Error";</p><p>$http_code["501"] = "Not Implemented";</p><p>$http_code["502"] = "Bad Gateway";</p><p>$http_code["503"] = "Service Unavailable";</p><p>$http_code["504"] = "Gateway Timeout";</p><p>$http_code["505"] = "HTTP Version Not Supported";</p><p><span style="font-size: 14px;"><span style="color: rgb(51, 51, 51); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);">①出现报错的“invalid User-Agent header”相关解决办法可参考《</span><a href="https://panxu.net/article/8389.html" target="_blank">php curl抓取远程图片报错:"invalid User-Agent header"解决办法</a>》一文。</span></p><p>好了,以上就是“php curl请求中http_code状态码详解”的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流。</p>