1

I'm working on a simple get with search parameters, trying to use Angular's httpclient with HttpParams

  getOptions(id1: string, id2: string): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
  var params: HttpParams = new HttpParams();
  params.set('id1', id1;
  params.set('id2', id2);
  this.httpClient.get<string[]>(`${this.appConfig.apiUrl}/api/task/getoptions`, {params: params}).subscribe(resp => {
    resolve(resp);
  }, error => {
    reject(error);
  })
});
}

My endpoint looks like that:

    [HttpGet("[action]")]
    public async Task<List<string>> GetOptions([FromQuery] string id1, [FromHeader] string id2)
    {
        //...do something
    }

I tried all attributes like [FromQuery], [FromForm], [FromHeader],... but the data I send never arrives to the controller, although method/endpoint is being called. The values are just null.

What am I doing wrong, or what am I missing?

1 Answer 1

1

and finally I found that the solution is on stackoverflow already...

Angular HttpClient params with method GET do not work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.