문제

I'm using Curb to get various URLs, and if the response is 200, I get what I need. However, if the response is a redirect, Curb doesn't seem to follow the redirects, even though I ask it to - e.g:

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'

However, if I do curl -L http://stats.berr.gov.uk/ed/vat/VATStatsTables2a2d2007.xls on the command line, I get the expected response. What am I doing wrong?

도움이 되었습니까?

해결책

It sounds as this server returns an empty reply[1] if you do not provide an user agent.

To solve you problem just set one:

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

[1]: curl -A '' -L http://stats.berr.gov.uk/... gives (52) Empty reply from server.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top