I am trying to set the header for a single post request using restangular but the request is being sent as plain text instead of json. I have read the documentation here as wel
You can do:
const headers = { headers: { 'Content-Type':'application/json' } };
RestServ.wandem.withHttpConfig(headers).post(pip)
After groping around the web, I found that restangular sends form data to the server in json format by default. I was misguided by the developer tools from chrome. In order to disect http requests I recommend fiddler If one wants to format the header in restangular being sent as a request from the form you can do the following:
//From the previous example....
//Assuming restangular did not not send form data in json format by default
$scope.getWanPip = function(pip){
RestServ.wandem.post(pip, {},{}, {'Content-Type':'application/json'}).then(function(res){
console.log(res)
}, function(err){
console.log('Error!!!\n', err);
})
Note the two empty curly braces instead of one... I can't still perform the post but this is because the data is being sent as part of the url instead of separately. This calls for another question...
Don't pass two empty objects, try passing:
.post(pip, undefined, undefined, {'Content-Type':'application/json'})
Or even .customPOST()
instead of .post()
.