Rumah > Soal Jawab > teks badan
P粉4587250402023-08-21 10:51:25
Saya rasa masalah anda adalah jsfiddle
只能处理form-urlencoded
请求。但是正确的方法是将正确的json
lulus sebagai badan permintaan:
fetch('https://httpbin.org/post', { method: 'POST', headers: { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, body: JSON.stringify({a: 7, str: 'Some string: &=&'}) }).then(res => res.json()) .then(res => console.log(res));
P粉8199374862023-08-21 10:15:17
Cara menggunakan data ES2017 async/await
支持,这是如何进行POST
JSON:
(async () => { const rawResponse = await fetch('https://httpbin.org/post', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({a: 1, b: 'Textual content'}) }); const content = await rawResponse.json(); console.log(content); })();