HttpClient sending header 'type' instead of 'content-type' on android

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

@mhartington can you please help me?

Is there only this one header declaration in your code? Or do you set it for every different request separately?

If so, check, if you forgot the single quotes around Content-Type ('Content-Type') somewhere.

There is only one declaration of headers in my code. it happens randomly. e.g. there is a button on my page which sends a post request to server, if i press that button 10 times, 2-3 times request will be sent with header ‘content-type’ and remaining 6-7 header will be ‘type’.

You use the HttpClient provider and not the Http provider, right?

How are you logging the headers on android where the error occurs?

Yes I am using HttpClient provider and i am logging headers on backend(Laravel 5.5 php)

And when you log these with chrome dev tools on your android device you get the right headers? Then I would assume, that it is a problem with laravel. Maybe you should ask this question regarding laravel in stackoverflow or a laravel support forum.

with chrome debugging erverything works fine. may be some issue with android’s implementation of http client

You could try the http plugin from ionic native, which sends request from the native android platform instead of the webview.

Thanks :slight_smile: .
I’ll try it and will let you know