2016-04-15 29 views
0

curlとPowerShellに関する質問があります。curl SOAPリクエスト

自分のサーバー(Windows Server 2008 R2 Enterprise)にgitをインストールしましたが、PowerShell git/bin/curlから電話しています。

$tempFile = [IO.Path]::GetTempFileName() | Rename-Item -NewName { $_ -replace 'tmp$', 'xml' } –PassThru 
$soupRequestXML | Set-Content $tempFile -Encoding UTF8  

cd $env:temp 
$cmd = "C:\Program Files (x86)\git\bin\curl -X POST -H `'Content-type:text/xml;charset:UTF-8`' -d `@" + $tempFile.name + " "+ $soapService 
Invoke-Expression $cmd 

ここで、$soupRequestXMLは私の石鹸リクエストです。

問題は、PowerShellが@文字を解析する際に問題があることです。

これはPowerShellのエラーです:私はそれがドイツ語である知っているが、私は私のものではありませんサーバー上で動作

Invoke-Expression : Die Splat-Variable "@tmpCEA7" kann nicht erweitert werden. Splat-Variablen können nicht als Teil eines Eigenschafts- oder Arrayausdrucks verwendet werden. Weisen Sie das Ergebnis des Ausdrucks einer temporären Variable zu, und führen Sie stattdessen einen Splat-Vorgang für die temporäre Variable aus.

申し訳ありません。あなたはすでに@という文字をエスケープしようとしていますが、まだ動作していません。

私もcurlに直接文字列を渡そうとしました:

$cmd = "C:\Program Files (x86)\git\bin\curl -X POST -H `'Content-type:text/xml;charset:UTF-8`' -d `'" + $(Get-Content $tempFile) + "`' "+ $soapService 

をしかし、curlはそれを解析するためにいくつかの問題を抱えているようですので、誰かがアイデアを持って?

curl: (6) Could not resolve host: <soapenv 
curl: (6) Could not resolve host: <soapenv 
curl: (6) Could not resolve host: <com 
curl: (6) Could not resolve host: <arg0>xx< 
curl: (6) Could not resolve host: <arg1>xxx< 
curl: (6) Could not resolve host: < 
curl: (6) Could not resolve host: <

これは私のSoapRequest XMLである:あなたのXML内の二重引用符の

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com=\"http://host...../"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <com:test> 
     <arg0>xx/arg0> 
     <arg1>xx</arg1> 
    </com:test> 
    </soapenv:Body> 
</soapenv:Envelope> 
+0

なぜあなたは 'Invoke-WebRequest'ではなく' curl'を使用していますか? –

+0

私はJava-DeveloperでPowershellの経験はあまりないので、また、これはPoweshell Version> 2.0でのみ動作するとも考えました。 – DaveTwoG

答えて

0

組み合わせ、物事をめちゃくちゃにされたコマンド文字列でInvoke-Expressionを使用。

コールオペレータ(&)を代わりに使用できる場合は、Inovoke-Expressionを使用しないでください。頭が痛むほど逃げることはありません。 XML文字列の二重引用符を一重引用符で置き換えて、それらを邪魔にならないようにします。それと

& "C:\Program Files (x86)\git\bin\curl" -X POST ` 
    -H 'Content-type:text/xml;charset:UTF-8' ` 
    -d "$((Get-Content $tempFile) -replace '"',"'")" $soapService 

あなたはPowerShellを使用している場合は、とにかくそれがInvoke-WebRequest使用する方が理にかなって思い、言った:

[xml]$data = Get-Content $tempFile 
$headers = @{'SOAPAction' = '...'} 
Invoke-WebRequest -Method POST -Uri $soapService -ContentType 'text/xml;charset="UTF-8"' -Headers $headers -Body $data 

かをSystem.Net.WebRequestクラスを(あなたは、PowerShellのV2で立ち往生しているように見えるので) :

[xml]$data = Get-Content $tempFile 

$req = [Net.WebRequest]::Create($soapService) 
$req.Headers.Add('SOAPAction', '...') 
$req.ContentType = 'text/xml;charset="utf-8"' 
$req.Method = 'POST' 

$stream = $req.GetRequestStream() 
$data.Save($stream) 
$stream.Close() 

$rsp = $req.GetResponse() 
$stream = $rsp.GetResponseStream() 
[xml]$result = ([IO.StreamReader]$stream).ReadToEnd() 
$stream.Close() 
+0

完璧な作品です:-)。 PowerShell v2の標準soapRequestに変更しました。 @Ansgar Wiechers:あなたの助けを借りて非常にThx – DaveTwoG

関連する問題