Angularjs ignores content-type for GET requests

Asked

Viewed 56 times

3

In my Angular 1 application, I’m using $httpProvider to be able to set the content-type by default in all methods, but for GET methods, it does not send in its header. How can I force the angular to set the content-type in GET methods?

In config

$httpProvider.defaults.headers.common['Content-Type'] = 'application/json';

Console

inserir a descrição da imagem aqui

Request

inserir a descrição da imagem aqui

1 answer

2


This is the right and expected behavior.

Methods HTTP GET and DELETE do not have payload; both clients and servers are not required to implement interpreters for a header content-Type in these operations.

The methods they carry payload, as POST or PUT, may contain the header in your requests.

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type

  • 1

    That’s what I’m talking about. Looking at the angular JS, the class responsible for sending requests to the server itself deletes the content-type when there is no payload in the request.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.