gpt4 book ai didi

xml - 如何使用 Postman 将参数作为 XML 字符串发布

转载 作者:行者123 更新时间:2023-12-02 03:37:13 26 4
gpt4 key购买 nike

我想使用 postman 将 xml 发布到网络服务。下面是原始正文 xml。参数“xml”是我想传递的字符串值,但是,由于语法错误,请求状态返回 400。我怀疑这是因为参数值被格式化为 xml。

在我的实际应用程序中一切正常,如果我想使用 postman 进行测试,我无法让它正常工作。

如何将此参数作为字符串发送?

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<SaveLead xmlns="http://tempuri.org/">
<xml>
<enquiry><Lead Ref='1234' Source='SourceDesc'><Contact FirstName='TestN' Surname='TestS' Email='testn@test.co.za' Mobile='0830000000' /></Lead></enquiry>
</xml>
</SaveLead>
</soap:Body>
</soap:Envelope>

网络服务 soap 请求示例

POST /webservice1.asmx HTTP/1.1
Host: xxxxx
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/SaveLead"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SaveLead xmlns="http://tempuri.org/">
<xml>string</xml>
</SaveLead>
</soap:Body>
</soap:Envelope>

最佳答案

根据上面 Danny 的评论,使用 CDATA 部分转义 XML 字符串解决了这个问题。

Definition: CDATA sections may occur anywhere character data may occur; they are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string <![CDATA[ " and end with the string " ]]>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<SaveLead xmlns="http://tempuri.org/">
<xml>
<![CDATA[ <enquiry><Lead Ref='1234' Source='SourceDesc'><Contact FirstName='TestN' Surname='TestS' Email='testn@test.co.za' Mobile='0830000000' /></Lead></enquiry> ]]>
</xml>
</SaveLead>
</soap:Body>
</soap:Envelope>

关于xml - 如何使用 Postman 将参数作为 XML 字符串发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49793079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com