tags:

views:

38

answers:

2

how to send a post request and get the response in ruby

request is,

name=$name_val

URL is http://example.com/a/2

how do i do this in python or ruby?

A: 

For Ruby you'll find the answer here: Net::HTTP

kschaper
+1  A: 

To do this in python:

import urllib
data = urllib.urlencode({
   "fieldName1" : "Val1", 
   "fieldName2" : "Val2", 
   "fieldName3" : "Val3"
})
f = urllib.urlopen("http://example.com/a/2", data)
html = f.read() # this is the response
Martin
sorry, this did not work, it doesn't display any result.
matt jack
fieldName is the post name e.g. <input type="hidden" name="fieldName1" value="Val1" />. When this is posted it sends the data to this url http://example.com/a/2 then html = f.read() returns the contents of the html page that would be displayed if you did this through a browser. If you don't have any content on this page then you won't get anything back.
Martin