xml - 从 Linux 发送 SOAP 请求时出现意外字符
问题描述
我试图发送一个 SOAP 请求。
curl -X POST -H "Content-Type: text/xml" -H "SOAPAction: " --data-binary file.xml https://endpoint.com
我将 xml 文件中的请求正文指定为 -
<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>
当我从 Mac 发送请求时,此文件工作正常。但是,当我将文件从 Mac 复制到 Linux 并尝试相同的命令时,我遇到了无效字符问题 -
<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>%
我尝试转义内容,但仍然遇到相同的错误-
<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>
谁能帮我?从 Linux 发送请求时,我应该如何编码 xml 请求正文?
解决方案
很可能它正在发送包含文字 text 的 POST 数据file.xml
。
尝试:
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.
推荐阅读
- gstreamer - Gstreamer - 要读取到多个客户端的流
- sql - 营业时间重新设计
- python - 使用 2D 滤波器卷积 3D 图像
- c++ - C ++变量mysql_query到数据库
- javascript - JS 不会仅在 iPhone (iOS 13) 上更新 DOM
- php - 如何防止jquery中的多个php脚本在按钮单击时执行
- java - 黄瓜抛出 java.lang.NoClassDefFoundError: io/cucumber/core/gherkin/FeatureParser
- php - Magento 2 Docker Crontab 和系统升级
- docker - 如何从容器内部访问 docker compose 安装的卷
- javascript - 如何在 ASP.NET Core 3 中使用 Ajax-Function 将 PartialView 插入到普通视图中?