简体   繁体   English

在将api请求发送到服务器时将api更改POST请求更改为GET请求

[英]fetch api change POST request to GET request when send it to the server

在此处输入图片说明

I experienced very weird bug during using fetch API. 使用fetch API时遇到了非常奇怪的错误。 As the picture above shows, the method property of Request is POST , but fetch send the request using GET method. 如上图所示, Requestmethod属性为POST ,但fetch使用GET方法发送请求。

Also, among three macbooks, two macbooks(one Catalina beta, one Mojave) experienced the same bug, but one macbook(Mojave) did not. 另外,在三台Macbook中,两台Macbook(一台Catalina beta版,一台Mojave)遇到相同的错误,而一台Macbook(Mojave)没有。 The last one just works perfectly. 最后一个效果很好。

All three machines used same Wifi network and same version of Chrome. 所有三台机器都使用相同的Wifi网络和相同版本的Chrome。

Where can I start to solve this bug? 我从哪里可以解决这个错误? Any kind of suggestion will be very helpful. 任何建议都会非常有帮助。 Thanks! 谢谢!

I think you have to check your two urls, it is different 我认为您必须检查两个网址,这是不同的

not same url 不一样的网址

Look at the log message closely, it says: 仔细查看日志消息,它说:

 redirected: true 

So you are making a POST request, but the server responds with a redirect response so the browser follows the redirect and makes a GET request to the new URL. 因此,您正在发出POST请求,但是服务器以重定向响应进行响应,因此浏览器会遵循重定向并向新URL发出GET请求。 This is handled transparently by the fetch API. 这由fetch API透明地处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM