首页 > 解决方案 > Linux,Curl,发送没有 xml 文件的 -X POST

问题描述

我在 Linux 中有一个带有 curl 的 -X POST 的小 sh 脚本:

curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" --data @\u\ManInTheMiddle.xml  | grep -o 'true\|false'

这工作正常,但我必须先编写 ManInTheMiddle.xml,第二步我可以发送 curl 命令。

中间人.xml

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <InsertPruefResultatFromXMLFile xmlns="http://tempuri.org/">
            <FilePath>\\serverip\script.xml</FilePath>
        </InsertPruefResultatFromXMLFile>
    </Body>
</Envelope>

有没有办法在没有 xml 文件的情况下做到这一点?直接发送“\serverip\script.xml”

喜欢:

curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" --d "\\serverip\script.xml"  | grep -o 'true\|false'

有任何想法吗?

EDIT1:我只想使用 ManInTheMiddle.xml 处理中间步骤,以便服务器直接获取到导入文件 (\serverip\script.xml) 的链接。

EDIT2:使用python它可以工作:

url = "http://serverip/WebServices/WebServiceSQLTestresult.svc?wsdl"

import suds
import suds.client
client = suds.client.Client(url)
result = client.service.InsertPruefResultatFromXMLFile("\\\\serverip\script.xml")

谢谢你...

标签: xmllinuxcurl

解决方案


$() 进行救援,替换

--data @\u\ManInTheMiddle.xml

--data-raw "$(curl --silent \\serverip\script.xml)"

就像是

curl -X POST http://serverip:8081/WebServices/WebServiceSQLTestresult.svc?wsdl -H "Content-Type: text/xml; charset="utf-8"" -H "SOAPAction: "http://tempuri.org/IWebServiceSQLTestresult/InsertPruefResultatFromXMLFile"" --data-raw "$(curl --silent \\serverip\script.xml)"  | grep -o 'true\|false'

请注意,我知道 $() 的可移植性如何,例如它肯定不能在微软的 cmd.exe 上运行,但至少它可以在 bash 上运行


推荐阅读