[英]Fetch HTTP request using XML
我正在尝试向这个 API 发出请求,当在浏览器中提交我的 XML 数据时,它工作正常,但我看不到它与提取 API 一起工作。我得到 STATUS 200 OK 但没有数据。 我很确定我没有正确提交正文,但无法弄清楚为什么?
直接在浏览器中提交时检查控制台与我的应用程序相比,我可以看到数据是用我似乎丢失的“参数”提交的?
感谢任何指导。
const xml =
'<GetOrderStatus><ClientID>FITE****</ClientID><UserID>FI****</UserID><Password>*****</Password><SecurityKey>*****/SecurityKey><Order><OrderNum>1834006076</OrderNum></Order></GetOrderStatus>';
fetch('http://api.3linx.com/v4/getorderstatus', {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'en-GB',
'Accept-Encoding': 'gzip, deflate',
Connection: 'Keep-alive',
},
body: xml,
})
.then((response) => response.text())
.then((text) => console.log(text));
由于您使用application/x-www-form-urlencoded
,因此您必须使用URLSearchParams
来发送带有params:
。
const xml = '<GetOrderStatus><ClientID>FITE****</ClientID><UserID>FI****</UserID><Password>*****</Password><SecurityKey>*****/SecurityKey><Order><OrderNum>1834006076</OrderNum></Order></GetOrderStatus>'; const form = new URLSearchParams(); form.append('params', xml); fetch('http://api.3linx.com/v4/getorderstatus', { method: 'POST', mode: 'no-cors', headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Accept-Language': 'en-GB', 'Accept-Encoding': 'gzip, deflate', Connection: 'Keep-alive', }, body: form, }).then((response) => response.text()).then((text) => console.log(text));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.