如何查看通过rails应用程序发送的HTTP请求?
问题描述:
我正在尝试与第三方网站进行交互,并且沟通如下。如何查看通过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应用程序,以便调试,今后这些问题发送。
任何想法?
答
我不会为你的任务推荐Wireshark,但会建议OWASP WebScarab