views:

246

answers:

3

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?

+3  A: 

You could use a network protocol analyzer tool like Wireshark.

dhofstet
A: 

grab favorite search engine for "HTTP proxies" for your favorite browser


http://www.delorie.com/web/headers.html

http://www.blunck.info/iehttpheaders/iehttpheaders.html

(if IE your favorite browser!)

https://addons.mozilla.org/en-US/firefox/addon/6647

http://www.4guysfromrolla.com/webtech/111208-1.shtml

Gene T
+1  A: 

I wouldn't recommend Wireshark for your task but would suggest OWASP WebScarab

jm04469