I am using ionic 3 with laravel 5.5 back-end. in some cases ionic’s httpclient sends ‘Type’ header instead of ‘Content-Type’. In case of ‘Type’ header i don’t receive data on my back-end.
I am making headers like this:
var headers = {
headers: new HttpHeaders({ ‘Content-Type’: ‘application/json’, ‘Authorization’: user.token_type + ’ ’ + user.access_token })
};
and i am receiving following headers on my backend (i’ve logged only header keys here):
1:
array (
0 => ‘host’,
1 => ‘connection’,
2 => ‘content-length’,
3 => ‘accept’,
4 => ‘origin’,
5 => ‘authorization’,
6 => ‘user-agent’,
7 => ‘type’,
8 => ‘accept-encoding’,
9 => ‘accept-language’,
10 => ‘x-requested-with’,
)
2:
array (
0 => ‘host’,
1 => ‘connection’,
2 => ‘content-length’,
3 => ‘accept’,
4 => ‘origin’,
5 => ‘authorization’,
6 => ‘user-agent’,
7 => ‘content-type’,
8 => ‘accept-encoding’,
9 => ‘accept-language’,
10 => ‘x-requested-with’,
)
only difference is ‘content-type’ is replaced by ‘type’ in some post requests.
Post request code:
var param = { parameter_value: { parameter_id: 1, value: ‘value’}};
var headers = {
headers: new HttpHeaders({ ‘Content-Type’: ‘application/json’, ‘Authorization’: user.token_type + ’ ’ + user.access_token })
};
return this.http.post(this.configProvider.get_base_url() +’/some_api’, param, headers);
I’ve tested this on browser and android. For web everything is working fine but in case of android this issue happens randomly for some requests.
If i debug the code running on android using chrome://inspect, this issue doesn’t happen
.