1

This seemed pretty straightforward:

  • capture a POST in Fiddler (Windows, because I find it easier to use than WireShark)
  • get data posted
  • make a similar POST using Net::Http in Ruby

And yet. Every time I run the post, it gets a 500. Could really use a suggestion here.

Original POST (Raw):

POST http://www.example.com/products/ajax HTTP/1.1
Host: www.example.com
Connection: keep-alive
Content-Length: 154
Origin: http://www.example.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://www.example.com/products
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

q=getProducts&page=52&type=leaf_blowers

But when I get this in the Rails console:

>> res = http.post_form URI.parse(the_url), {'a' => 'getProducts', 'page'=> '52', 'type'=> 'leaf_blowers'}
=> #<Net::HTTPInternalServerError 500 Internal Server Error readbody=true>

The first one (Fiddler) results in HTML being returned. The second is just a 500 error. Is there anything obvious that I'm missing here? If you'd like to see the Wireshark capture, let me know how I can get it to look like the Fiddler raw capture -- I can't figure out how to get that detail out of Wireshark.

jcollum
  • 43,623
  • 55
  • 191
  • 321
  • Why would you use wireshark? just proxy it through fiddler then you can compare them side by side. – pguardiario Apr 09 '12 at 03:26
  • @pguardiario that's a good idea, do you have any links that explain how to do that? – jcollum Apr 09 '12 at 15:52
  • Fiddler is probably running on localhost:8888 and here is some info on setting http proxy: http://ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/Net/HTTP.html#method-c-Proxy Also you might consider mechanize which makes things easier imo. – pguardiario Apr 10 '12 at 00:12

1 Answers1

1

Maybe it's a typo when you posted the question, but the original post has

q=getProducts

and then you make the request with:

'a' => 'getProducts'

What happens if you make the request with 'q' => 'getProducts' ?

luis.parravicini
  • 1,214
  • 11
  • 19