Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby路缘不遵循重定向_Ruby_Http_Curl_Curb - Fatal编程技术网

Ruby路缘不遵循重定向

Ruby路缘不遵循重定向,ruby,http,curl,curb,Ruby,Http,Curl,Curb,我正在使用路缘来获取各种URL,如果响应是200,我就会得到我所需要的。但是,如果响应是重定向,则路缘似乎不会遵循重定向,即使我要求它-例如: easy = Curl::Easy.new easy.follow_location = true easy.max_redirects = 3 easy.url = "http://stats.berr.gov.uk/ed/vat/VATStatsTables2a2d2007.xls" easy.perform => Curl::Err::G

我正在使用路缘来获取各种URL,如果响应是200,我就会得到我所需要的。但是,如果响应是重定向,则路缘似乎不会遵循重定向,即使我要求它-例如:

easy = Curl::Easy.new
easy.follow_location = true
easy.max_redirects = 3 
easy.url = "http://stats.berr.gov.uk/ed/vat/VATStatsTables2a2d2007.xls"
easy.perform

=> Curl::Err::GotNothingError: Curl::Err::GotNothingError
from /Users/stuart/.rvm/gems/ruby-2.0.0-p0@datakitten/gems/curb-0.8.4/lib/curl/easy.rb:60:in `perform'

但是,如果我执行
curl-Lhttp://stats.berr.gov.uk/ed/vat/VATStatsTables2a2d2007.xls
在命令行上,我得到了预期的响应。我做错了什么?

如果您不提供用户代理,听起来好像此服务器返回了一个空回复[1]

要解决您的问题,只需设置一个:

...
easy.useragent = "curb"
easy.perform

[1] :
curl-A'-Lhttp://stats.berr.gov.uk/...
从服务器上给出
(52)空回复

明白了!谢谢我遇到了同样的问题
easy.follow\u location=true
为我解决了。