Ricky
Ricky

Reputation: 763

How can I view HTTP requests being sent through a rails application?

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?

Upvotes: 1

Views: 1019

Answers (2)

McGovernTheory
McGovernTheory

Reputation: 6664

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

Upvotes: 1

dhofstet
dhofstet

Reputation: 9964

You could use a network protocol analyzer tool like Wireshark.

Upvotes: 3

Related Questions