我正在尝试发送SOAP请求。
response = driveservice.list(
q="name='June 2019' and mimeType='application/vnd.google-apps.folder'",
spaces='drive'
).execute()
for item in response.get('files', []):
# process matched item
我在xml文件中将请求正文指定为-
curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: " --data-binary file.xml https://endpoint.com
当我从Mac发送请求时,此文件工作正常。但是,当我将文件从Mac复制到Linux并尝试相同的命令时,遇到无效字符问题-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dse="http://brandmaker.com/webservices/dse/v2/">
<soapenv:Header/>
<soapenv:Body>
<dse:findById>
<id>1405</id>
</dse:findById>
</soapenv:Body>
</soapenv:Envelope>
我尝试转义内容,但仍然遇到相同的错误-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body> .
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Error reading XMLStreamReader: Unexpected character 'f' (code 102) in prolog; expected '<' at [row,col {unknown-source}]: [1,1]</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>%
有人可以帮助我吗?从Linux发送请求时,应该如何编码xml请求正文?
答案 0 :(得分:1)
很可能它正在发送包含文字file.xml
的POST数据。
尝试:
curl -X POST \
-H "Content-Type: text/xml" \
-H "SOAPAction: " \
--data-binary @file.xml \
https://endpoint.com
对于Linux,--data-binary
的文档为:
--data-binary <data>
(HTTP) This posts data exactly as specified with no extra processing whatsoever.
If you start the data with the letter @, the rest should be a filename.
Data is posted in a similar manner as --data-ascii does, except that newlines
and carriage returns are preserved and conversions are never done.
If this option is used several times, the ones following the first will
append data as described in -d, --data.