ChocapicSz ChocapicSz - 4 years ago 91
Ruby Question

Posting data in ruby

I am new in ruby and I have not got much experience with posting datas over web-servers.
I need to POST some data to a webservice written in asp .net.
The url is like:


I've tried to post using TCPSocket and RestClient but I couldn't.

Can anyone give me any solution?

Answer Source

You need Net::HTTP class.

First you need to create valid URI:

require 'uri'
uri = URI.parse('http://localhost:8080')

Then create new Net::HTTP object

require 'net/http'
http =, uri.port)

From now on you can send requests using methods like get and post. To send a hash simply do:'/TheService.asmx/CollectData', {hash: 'data', foo: 'bar'}.to_query)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download