3

I want to use a body in my GET request. I am not finding any way to do it with Angular 2/4.

I Found the body attribute in the RequestOptionsArgs class, but it is not sending in the http request.

With httpie.org it's possible to send it like this :

http --verbose GET 'http://localhost/api/test' 'Content-Type: application/json' 'foo=bar'

This is sending this raw request:

GET /api/test HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 14
Content-Type: application/json
Host: localhost
User-Agent: HTTPie/0.9.9
enter code here
{
    "foo": "bar"
}

this.http.get("/api/test", {body: JSON.stringify{foo: "bar"}})
SakiiR
  • 131
  • 2
  • 12

1 Answers1

3

By using Angular 2/4 you cannot send body. in general you can send a request body with GET but it should not have any meaning. If you give it meaning by parsing it on the server and changing your response based on its contents, then you are ignoring this recommendation in the HTTP/1.1 spec, section 4.3

Rahul Cv
  • 725
  • 5
  • 12