Calling Yahoo REST web services with Ruby query parameter problems

29 November, 2006

I’m an idiot and req ='?'+url.query) is my friend.

Just playing around with Ruby and the Yahoo Web Services. The example they give for calling a web service is this:

require 'net/http'

url = ''
resp = Net::HTTP.get_response(URI.parse(url)) # get_response takes an URI object

data = resp.body

I am behind a proxy at work, so my code looks like this:

require 'net/http'

@proxy_addr = ''
@proxy_port = 3128

url = URI.parse('')

req =
res = Net::HTTP::Proxy(@proxy_addr, @proxy_port).start(, url.port) {|http|

data = res.body

puts data

The response I get is:

<?xml version="1.0" encoding="UTF-8"?>
<Error xmlns="urn:yahoo:api">
  The following errors were detected:
  <Message>invalid value: appid (empty or missing)</Message>
  <Message>invalid value: query (empty or missing)</Message>
<!-- uncompressed Wed Nov 29 05:54:50 PST 2006 -->

So the query parameters are being stripped from the GET request. I have no idea why. Any ideas? I’ve not had this problem with making queries through our proxy, although a look with Wireshark could prove that they’re making it through.

Oops – I think I’m actually stripping the parameters myself there by creating a new Get using url.path but even changing to just do a puts http.request_get('WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=1').body doesn’t work, which I thought might have had a better chance.

See other posts tagged with general and all posts made in November 2006.