如何解决使用XML提取HTTP请求
我正在尝试向该API发出请求,该请求在浏览器中使用XML数据提交时可以正常工作,但是我看不到将其与fetch 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));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。