私は第三者のウェブサイトとのインターフェースを試みており、その通信は次のようになります。railsアプリケーション経由でHTTPリクエストを送信する方法を教えてください。
私はRailsので働いている、と私は、これはネット:: HTTPを使用して設定を取得しようとしている
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?> <LabelRequestResponse> ... </LabelRequestResponse>
この応答を受け取る。この要求
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>
を送信します。私はいくつかのことを試しましたが、私の最高の結果は "既存の接続はリモートホストによって強制的に閉じられました。"ここに私の試みの例があります。
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リクエストを見ることができる方法を知りたいのです。
アイデア?