【发布时间】:2021-04-01 22:22:43
【问题描述】:
我在 Postman 中设置了一个 GET 请求,其中包含如下原始正文数据,它可以正常工作。我可以从服务器获取数据
但是我的 Js fetch api 我不确定如何向它添加请求正文数据。 这是我的 GET 请求配置
var requestOptions = {
method: 'GET',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://example.net:/app/v1/cmp/displacer/url", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
但它返回错误
error TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Request with GET/HEAD method cannot have body.
服务器只接受对该 URL 的 GET 请求。 我试图用谷歌搜索但没有运气。 感谢您的宝贵时间。
【问题讨论】: