2009-07-26 29 views
5

SOAP Webサービスにリクエストしたいが、宝石をインストールしたくない。 単純なXMLを使用してリクエストを行う方法はありますか?RailsでXMLを使用してSOAPリクエストを作成する

すべての実装/チュートリアルが宝石を使用していたので、私はそれが些細なことだと思っています。

私はSOAP応答は、XML応答の権利としても扱うことができると思いますか?

要求はこれです:あなたはこれを行うことができ

POST /services/tickets/issuer.asmx HTTP/1.1 
Host: demo.demo.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <Tick xmlns="http://demo.com/test/test"> 
     <Request> 
     <Username>string</Username> 
     <Password>string</Password> 
     <AcquirerId>int</AcquirerId> 
     <RequestType>string</RequestType> 
     <ExpirePreauth>unsignedByte</ExpirePreauth> 
     <BitPerSec>int</BitPerSec> 
     <Office>string</Office> 
     </Request> 
    </Tick> 
    </soap12:Body> 
</soap12:Envelope> 

答えて

6

def post_xml(path, xml) 
    host = "http://demo.demo.com" 
    http = Net::HTTP.new(host) 
    resp = http.post(path, xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8' }) 
    return resp.body 
end 

をXML応答は、このメソッドによって返されます。

+0

Ruby 1.9.2とRails 3.2.12を使用する - ホスト名から「http://」を削除する必要がありました。また、SOAP 1.1を使用し、 'Content-Type'を 'text/xml'に設定しなければなりませんでした。ありがとう! – Josh

+1

私は同様の問題を解決しようとしており、同様のソリューションを設定しています。しかし、私が投稿しようとしているサーバーにはユーザー認証が必要です。資格情報の設定に関するヒントはありますか? –

+0

この 'path'変数は何ですか? – Arpit