2017-04-03 16 views
0

次のpowershellスクリプトを使用して、テキストファイル(soap.txt)に格納されたXMLデータをエンドポイントに送信しています。Powershell:Invoke-WebRequest

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" 
$headers.Add("charset", 'utf-8') 
$headers.Add("SOAPAction", 'nms:rtEvent#PushEvent') 

Invoke-WebRequest http://localhost:8080/nl/jsp/soaprouter.jsp -Method Post -ContentType 'text/xml' -Headers $headers -InFile D:\Scripts\archive\soap.txt 

上記の方法がうまく働く一方で、私は、コンテンツを充実させることができますように、代わりに-bodyのparamを使用したいが、私はいくつかの問題に直面しています、以下のコードがあります。

## Set SOAP headers 
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" 
$headers.Add("charset", 'utf-8') 
$headers.Add("SOAPAction", 'nms:rtEvent#PushEvent') 
$url = "http://localhost:8080/nl/jsp/soaprouter.jsp" 

$body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:nms:rtEvent"> 
    <soapenv:Header/> 
    <soapenv:Body> 
      ...etc etc 
    </soapenv:Body> 
</soapenv:Envelope>' 

Invoke-WebRequest -Method Post -Uri $url -Headers $headers -Body $body -ContentType 'application/xml' 

私は次のエラー

powershell error

を取得しています私も

$body = @" 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:nms:rtEvent"> 
    <soapenv:Header/> 
    <soapenv:Body> 
...rest of code here asd 
    </soapenv:Body> 
</soapenv:Envelope> 
"@ 
Invoke-WebRequest -Method Post -Uri $url -ContentType 'text/xml' -Headers $headers -Body $body 

を試みたと私はヘッダがappropiateプロパティやメソッドを使用して変更しなければならないことを取得するには、ので、ヘッダーにコンテンツの種類を追加しますが、どちらも動作しません、私はpowershell 3.0を使用しています

enter image description here

+0

あなたは流行している内容を共有してください。 –

+0

@RanadipDutta本質的に$ body変数で定義されているのと同じ内容ですが、私はちょうど機密情報を削除しました。単純なxml SOAP –

+0

Fine。私はそれを通過して、サンプルを作成しましょう。 –

答えて

0

答えは、変数のXMLインデントを削除することです。この問題はどこかで文書化されていますか?それは限界です。

$body = @" 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:nms:rtEvent"> 
<soapenv:Header/> 
<soapenv:Body> 
...rest of code here asd 
</soapenv:Body> 
</soapenv:Envelope> 
"@ 
+1

LOL ...いいことが行われました::) –