gpt4 book ai didi

android - React-native POST 请求正文

转载 作者:行者123 更新时间:2023-11-30 01:46:34 25 4
gpt4 key购买 nike

我需要向服务器发送一个没有任何正文的 POST 请求(登录 API)。我正在尝试在 Android 和 iOS 上使用 fetch 来执行此操作,但出现错误:“方法 POST 必须具有请求正文”
有没有禁用它的选项?我必须通过 POST 发送它并且没有正文。
我的代码:

fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => response.text())
.then((responseText) => { console.log(responseText); })
.catch((error) => { console.warn(error); });

最佳答案

我最近在尝试通过 application/x-www-form-urlencoded 发送 POST 时遇到了这个问题。我的解决方案是检查我的请求处理程序中的正文,如果请求是 POST 并且没有要指定的正文 body: '' 请求现在顺利通过。看起来 react-native 中的 fetch 实现只是在寻找 body 键。

关于android - React-native POST 请求正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33633706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com