I'm trying to interface with a 3rd party website, and the communication goes as follows.
Send this request
POST /Service/LabelService.asmx/GetLabelXML HTTP/1.1
Host: www.host.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length
labelRequestXML=<LabelRequest> ... </LabelRequest>
Receive this response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?> <LabelRequestResponse> ... </LabelRequestResponse>
I'm working with Rails, and so I'm trying to get this set up using Net::HTTP. I've tried a handful of things, however my best results are "An existing connection was forcibly closed by the remote host." Here's an example of one of my attempts.
require 'net/http'
require 'net/https'
require 'uri'
Net::HTTP.version_1_1
def get_shipping_label
url = URI.parse('www.host.com/LabelService/LabelService.asmx/BuyPostageXML')
header = {"Content-Type" => "application/x-www-form-urlencoded"}
data = "labelRequestXML=<LabelRequest></LabelRequest>"
http = Net::HTTP.start(url.host)
response, body = http.post('/LabelService/LabelService.asmx/BuyPostageXML', data)
end
Now my goal is obviously getting the communication to work, but more importantly I'd like to know how I could see the HTTP request being sent by my rails application in order to debug these problems in the future.
Any ideas?