question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP use body options in Get Method

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior Http using get method and pass body with options does not work.

Expected/desired behavior Please correct it to use body in method get. This is ok to post method but not to get method

Reproduction of the problem

This is my scenario

export class BuscaVagasService { private _rota = ‘http://localhost:49571/api/v0/busca-vagas’;

constructor(private _http: Http) { }

getVagas(dados: { [chave: string]: string[]; }): Observable<IResultadoBusca<IVaga>> {
    let body = JSON.stringify(dados);
    let headers = new Headers({ 'Content-Type': 'application/json' });

    var requestOptions = new RequestOptions({                    
        headers: headers,
        body: dados
    })

let retorno = this._http.get(this._rota,  requestOptions)
        .map((response: Response) => response.json() || {});

    return retorno;
}

What is the expected behavior?

pass body to webApi Method

What is the motivation / use case for changing the behavior?

To correct this

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4

  • Browser: [ Chrome 51.0.2704.103 ]

  • Language: [TypeScript]

  • **Web Api: .NET Core:

    [HttpGet]
    public ResultadoBusca<Vaga> Buscar([FromBody]Dictionary<string, List<string>> dados = null, [FromQuery]bool comFacets = true)
    {
        var parametros = this._buscaVagaService.ParsearArgumentos(dados);
    
        return this._buscaVagaService.Buscar(parametros, comFacets);
    }
    

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
sirajccommented, Jul 8, 2016

This is as designed. HTTP Get does not support body and hence the Angular’s Http does not support it either

8reactions
vicbcommented, Jul 9, 2016

IIRC the RFC does not prevent GET request from having a body but in practice most servers do not support this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP GET with request body - Stack Overflow
Yes, you can send a request body with GET but it should not have any meaning. If you give it meaning by parsing...
Read more >
GET - HTTP - MDN Web Docs
The HTTP GET method requests a representation of the specified resource. Requests using GET should only be used to request data (they ...
Read more >
Request bodies in GET requests - Evert Pot
So if we decided to use GET for our complex search, what can we do? Body is obviously not allowed; our only options...
Read more >
HTTP GET with Request body - Guidelines - TheCodeBuzz
HTTP GET with Request body guidelines and best practices . Specification clarifies support for GET method with body parameters with known ...
Read more >
REST API - HTTP GET with Request Body - Roy Tutorials
Here I am going to discuss about whether it is a good idea to send parameter in request body of the HTTP GET...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found