Restangular not setting headers on post

前端 未结 3 384
后悔当初
后悔当初 2021-01-27 19:40

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

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-27 20:25

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

提交回复
热议问题