本文介绍了从网页解析产生 405 Not Allowed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在提出这些问题之前,我一直在寻找解决方案,但不幸的是,它们都没有产生好的结果.访问此特定 url 时,我收到 OpenURI::HTTPError: 405 Not Allowed
:
I've been looking around for solutions before asking this questions but unfortunately none of them yielded good results.I get a OpenURI::HTTPError: 405 Not Allowed
when accessing this specific url:
require 'open-uri'
doc = Nokogiri::HTML(open("http://streeteasy.com"))
#=> OpenURI::HTTPError: 405 Not Allowed
from /Users/cyrusghazanfar/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:358:in `open_http'
也尝试过:
$ curl -I http://streeteasy.com
返回:
HTTP/1.1 405 Not Allowed
Date: Fri, 22 Sep 2017 20:03:59 GMT
Content-Type: text/html
Connection: keep-alive
Server: nginx
X-DZ: 24.193.31.96
Vary: Accept-Encoding
X-DZ: 127.0.0.1
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: private, no-cache, no-store, must-revalidate
Edge-Control: no-store, bypass-cache
Surrogate-Control: no-store, bypass-cache
推荐答案
问题是服务器需要一个 User-Agent
头来工作,所以在 curl 中它会像:
the problem is that the server needs an User-Agent
header to work, so in curl it would be like:
curl --header "User-Agent: Mozilla/5.0" http://streeteasy.com
这篇关于从网页解析产生 405 Not Allowed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!