Im trying to use Nets/HTTP to use POST
and put in a custom user agent. I've typically used open-uri
but it cant do POST
can it?
I use
resp, data = Net::HTTP.post_form(url, query)
How would I change this to throw custom headers in?
Edit my query is:
query = {'a'=>'b'}
You can't use
post_form
to do that, but you can do it like this:(Read the net/http documentation for more info)
I needed to post json to a server with custom headers. Other solutions I looked at didn't work for me. Here was my solution that worked.
Thanks due to Mike Ebert's tumblr: http://mikeebert.tumblr.com/post/56891815151/posting-json-with-nethttp
You can try this, for example: