我的Url参数太大了。因此,我试图通过在request.body
中传递它来获得这个内容。API在测试时可以很好地与postman一起工作。但是无法在React中获取它。
我用的是ExpressJS
API: http://localhost:5000/api/v1
React代码:
let result = await fetch("http://localhost:8080/autocomplete",{
method: 'GET',
body: {
"text": "something new"
}
});
console.log(await result.json()) // Not get my data here
错误:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have a body.
我是怎么解决这个问题的?
发布于 2021-12-06 08:36:55
这是意料之中的。
在mozilla中,它提到:The HTTP GET method requests a representation of the specified resource. Requests using GET should only be used to request data (they shouldn't include data).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
https://stackoverflow.com/questions/70242694
复制相似问题