首页 > Windows开发 > 详细

fetch 报错 Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

时间:2017-09-15 11:38:15      阅读:6922      评论:0      收藏:0      [点我收藏+]

标签:about   invalid   option   html   报错   doc   etc   use   argument   

TypeError: Failed to execute ‘fetch‘ on ‘Window‘: Request with GET/HEAD method cannot have body.

在“窗口”上执行“取”失败:GET / get方法的请求不能有正文。

 
 

GET requests can‘t have a request body, you can‘t make them have one. GET requests only retrieve data, they never send data.

An API that requires GET request with empty object as a body just doesn‘t work.

 

 

 

No, there isn‘t.

GET requests can‘t have a request body, you can‘t make them have one. GET requests only retrieve data, they never send data.

An API that requires GET request with empty object as a body just doesn‘t work.

Edit:

Apparently, GET requests are allowed to have a body. Most implementations will ignore it or reject the request. But even if the server that provides your API allows a body, you can‘t use it:

From the spec about XMLHttpRequest#send:

Initiates the request. The optional argument provides the request entity body. The argument is ignored if request method is GET or HEAD. Throws an "InvalidStateError" exception if the state is not OPENED or if the send() flag is set.

From the spec about the Request class in the fetch API:

If either init’s body member is present and is non-null or inputBody is non-null, and request’s method is GET or HEADthen throw a TypeError.

That means that the answer to your question is still No.

fetch 报错 Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

标签:about   invalid   option   html   报错   doc   etc   use   argument   

原文:http://www.cnblogs.com/winyh/p/7525395.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号