Angular v1.3.5
I'm trying to pass serialized data to my API. It requires the Content-Type header to be application/x-www-form-urlencoded; charset=UTF-8;
For POST, I've set this up as follows in my .run:
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8;";
This works great for POST. However, for PUT doing the same is completely ignored.
$http.defaults.headers.put["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8;";
I even tried putting this in the request. The Content-Type was still ignored.
$http({
method : 'PUT',
url : SMARTWORX_CONFIGS.APIURL + 'users/' + service.profile.id + '.json',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
},
data : {
user : profile
}
})
I've been forced to solve this by using an interceptor and adding the headers to the config object there. It's quite a hack, but it works.
Am I doing something wrong here?