我正在尝试使用以下代码验证是否存在远程网址:
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)
我仍然收到 405 Method not allowed。当我使用Get
反而Head
in Net::HTTP::Head.new
我得到了 200 Success,但也有整个远程文档响应,这导致了更长的响应时间(0.3s => 0.9s)。
有什么想法为什么会发生这种情况吗?谢谢
有一个机会,@endpoint
您尝试与之交互的 url 不支持 HEAD 请求(这确实很奇怪,但情况仍然可能如此)。你的代码对我来说工作得很好,有几个网址(google.com、stackoverflow.com 等)
您是否尝试过使用curl 请求来查看它返回的内容?
curl -I http://www.the_website_you_want_to_test.com
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)