Restangular not setting headers on post

ぐ巨炮叔叔 提交于 2019-12-02 09:39:26

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...

Franz

Don't pass two empty objects, try passing:

.post(pip, undefined, undefined, {'Content-Type':'application/json'})

Or even .customPOST() instead of .post().

You can do:

const headers = { headers: { 'Content-Type':'application/json' } };

RestServ.wandem.withHttpConfig(headers).post(pip)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!