Demiro-FE-Architect
Demiro-FE-Architect

Reputation: 3740

Angular4: HttpClient and HttpParams: passing an object as a value in httpParams.set()

I have a problem with more complex key value pair... what if I wanted to set for a value as an object?

I am having this problem:

const includeStr = JSON.stringify({include: 'match-timeline-events'});
const params: HttpParams = new HttpParams().set('filter', includeStr);

when I use it in:

this.http.get(environment.apiPath + '/clientMatches/' + id, {params})

I get in the headers then set this

(urlencoded): filter:%7B%22include%22:%22match-timeline-events%22%7D

but for some reason, the : doesn't get encoded and the string should've been

(urlencoded): filter:%7B%22include%22%3A%22match-timeline-events%22%7D

any ideas how to solve this?

Upvotes: 1

Views: 2084

Answers (1)

Estus Flask
Estus Flask

Reputation: 222379

This is possibly a bug that should be reported. Any way, you can address it with HttpParams custom encoder that can extend a default one, HttpUrlEncodingCodec.

As it can be seen, HttpUrlEncodingCodec uses a custom function that doesn't encode a colon on purpose.

Upvotes: 1

Related Questions