2009-07-18 62 views
1

我正在嘗試與第三方網站進行交互,並且溝通如下。如何查看通過rails應用程序發送的HTTP請求?

發送此

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> 

收到該響應

HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
<?xml version="1.0" encoding="utf-8"?> <LabelRequestResponse> ... </LabelRequestResponse> 

我與Rails的工作,所以我試圖讓這個設置使用的Net :: HTTP。我嘗試了一些東西,但是我最好的結果是「現有連接被遠程主機強行關閉。」這是我的一個嘗試的例子。

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 

我現在的目標顯然是讓通信工作,但更重要的是我想知道我怎麼能看到的HTTP請求由我的Rails應用程序,以便調試,今後這些問題發送。

任何想法?

回答

1

我不會爲你的任務推薦Wireshark,但會建議OWASP WebScarab

相關問題