使用XML提取HTTP请求

问题描述

我正在尝试向该API发出请求,该请求在浏览器中使用XML数据提交时可以正常工作,但是我看不到将其与fetch API配合使用。我得到STATUS 200 OK,但没有数据。我敢肯定我提交的尸体不正确,但无法弄清楚为什么?

在直接通过浏览器与我的应用程序一起提交时检查控制台,我可以看到数据是用“参数”提交的,我似乎丢失了该信息吗?

赞赏任何指导。

my response correct response

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,因此必须使用URLSearchParamsparams:发送数据。

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));

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...