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

Issue Description

HTTP GET call gives the below error when the GET method uses Body parameters.

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

The issue could also be visible using other languages like Node, Python, or Java.

The issue can be easily reproducible using tools like Postman or Swagger.

Resolution – Failed to execute ‘fetch’ on ‘Window’

RFC Specification

As per RFC 7231

GET is the primary mechanism of information retrieval and the focus of almost all performance optimizations.

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

After following the above specifications, I validated the .NET Core support for GET method with Body parameter.

[AllowAnonymous]
        [HttpGet]
        public IActionResult Token([FromBody]LoginModel login)
        {
            return Ok(login.Username);
        }

Surprisingly GET method was successful with [FromBody] parameters if executed using HttpClient or PostMan etc.

Although the specification clarifies support for the GET method with body parameters, it also warns us about its usage and clarifies that it is not useful to do.

I believe due to these uncertainties Swagger/Open API has not implemented this RFC yet.

We shall have to wait and see if they will implement the same in future releases.

So before using GET with the Body parameter, you must first ensure the servers are supporting it.

Some servers might ignore the body of GET requests or behavior like caching GET/HEAD requests might cause issues.

If you find any limitations on using GET with Body as per specification then one should use POST method as an alternative.

Apart from Swagger/Open API, I found GET with Body parameters is not supported in other tools like SOAP UI (Not supported), and Fiddler(Gives warning).

Other References:

Below are a few major limitations elaborating on the usage of the HTTP GET or DELETE method with body parameters with a few simple examples.

Did the above guidelines help in resolving your issue?

Please sound off in the comments below !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



2 thoughts on “Resolved: Failed to execute ‘fetch’ on ‘Window’: Request with GET cannot have the body

  1. Thanks for putting this details. This was very useful. This topic is bit confusing. I admire you for putting all the details in the link.

Leave a Reply

Your email address will not be published. Required fields are marked *