gpt4 book ai didi

ruby-on-rails - 如何查看通过 Rails 应用程序发送的 HTTP 请求?

转载 作者:可可西里 更新时间:2023-11-01 16:58:20 24 4
gpt4 key购买 nike

我正在尝试与第 3 方网站进行交互,通信过程如下。

发送这个请求

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

现在我的目标显然是让通信正常工作,但更重要的是我想知道如何查看我的 Rails 应用程序发送的 HTTP 请求,以便将来调试这些问题。

有什么想法吗?

最佳答案

您可以使用网络协议(protocol)分析器工具,例如 Wireshark .

关于ruby-on-rails - 如何查看通过 Rails 应用程序发送的 HTTP 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1148847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com