簡體   English   中英

使用 XML 獲取 HTTP 請求

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM