我有一个关于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 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>
为什么使用'curl'而不是'Invoke-WebRequest'? –
因为我是Java开发人员,而且我对PowerShell没有太多经验?我还认为这只适用于Poweshell版本> 2.0? – DaveTwoG