405在Net :: HTTP请求中不允许使用方法[在轨道上运行红宝石] [英] 405 Method not allowed on Net::HTTP request [ruby on rails]

查看:76
本文介绍了405在Net :: HTTP请求中不允许使用方法[在轨道上运行红宝石]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证是否存在带有以下代码的远程URL:

I'm trying to verify if there is a remote url with following code:

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方法不被允许.当我在 Net :: HTTP :: Head.new 中使用 Get 代替 Head 时,我获得200成功,但整个远程文档都在其中响应会导致响应时间更长(0.3s => 0.9s).

I'm still getting 405 Method not allowed. When I use Get instead Head in Net::HTTP::Head.new I'm getting 200 Success but also with whole remote document in response what results in bigger response time (0.3s => 0.9s).

有什么想法为什么会这样?谢谢

Any ideas why this is happening? Thx

推荐答案

您尝试与之交互的 @endpoint 网址有可能不支持HEAD请求(实际上很奇怪,但情况仍然如此).您的代码对我来说适合一些URL(google.com,stackoverflow.com等)

There's a chance that the @endpoint url you're trying to interact with doesn't support HEAD requests (which would be really weird, but still may be the case). Your code works fine for me with a handful of urls (google.com, stackoverflow.com, etc.)

您是否尝试过curl请求以查看返回的内容?

Have you tried a curl request to see what it returns?

curl -I http://www.the_website_you_want_to_test.com

这篇关于405在Net :: HTTP请求中不允许使用方法[在轨道上运行红宝石]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆