Mr *_*ack 3 ruby-on-rails http-headers
我正在尝试使用以下代码验证是否存在远程网址:
endpoint_uri = URI.parse(@endpoint.url)
endpoint_http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
endpoint_request = Net::HTTP::Head.new(endpoint_uri.request_uri)
endpoint_response = endpoint_http.request(endpoint_request)
Run Code Online (Sandbox Code Playgroud)
我仍然收到 405 Method not allowed。当我使用inGet时,我得到了 200 Success,而且还使用整个远程文档来响应,这导致了更长的响应时间(0.3s => 0.9s)。HeadNet::HTTP::Head.new
有什么想法为什么会发生这种情况吗?谢谢
@endpoint您尝试交互的 url有可能不支持 HEAD 请求(这确实很奇怪,但情况仍然可能如此)。你的代码对我来说工作得很好,有几个网址(google.com、stackoverflow.com 等)
您是否尝试过使用curl 请求来查看它返回的内容?
curl -I http://www.the_website_you_want_to_test.com
Run Code Online (Sandbox Code Playgroud)