Problem with Flickr API and net/http

K

Kyle Peyton

I'm writing an app that uses the flickr api via http requests. I can't
figure out if the problem I'm having is the way I'm implementing this
with net/http or simply a problem with the flickr api. My code looks
like this:

xml_data = Net::HTTP.get_response(URI.parse(url)).body
Hpricot(xml_data)

I know the url is valid, because I can paste the url directly in to my
browser and I get valid xml from flickr. But when I issue this code in
my app, I get a blank response. xml_data is an empty string every time
and I can't figure out why. Am I requesting a response incorrectly?
Anyone have any idea?

-Kyle
 
K

Kyle Peyton

Anyone have any problems with receiving blank responses from a Net::HTTP
request but then get a valid response when issuing the request in a
browser?
 
M

Matthias Reitinger

Kyle said:
I'm writing an app that uses the flickr api via http requests. I can't
figure out if the problem I'm having is the way I'm implementing this
with net/http or simply a problem with the flickr api. My code looks
like this:

xml_data = Net::HTTP.get_response(URI.parse(url)).body
Hpricot(xml_data)

I know the url is valid, because I can paste the url directly in to my
browser and I get valid xml from flickr. But when I issue this code in
my app, I get a blank response. xml_data is an empty string every time
and I can't figure out why. Am I requesting a response incorrectly?
Anyone have any idea?

Take a look at the HTTP response code (call .code instead of .body). If
it is in the 3xx range the server is redirecting you to a different URI.
A browser usually follows these redirects automatically.

-Matthias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top