2017-09-13 34 views
0

我有這個角度範圍函數,它負責發送POST請求。從角度url發佈請求隱藏參數

$scope.addStuff = function(p1, p2) { 
     $http.post('stufflist/addStuff/' + p1 + '/' + p2, 
        {}, 
        {params: {'value': stuffValue}} 
       ).then(function successCallback(response) { 

        }, function errorCallback(response) { 

        }); 
       }; 

然後,我有這樣的映射(我使用Spring的MVC):

@RequestMapping(value = "/addStuff/{p1}/{p2}", method = RequestMethod.POST) 
    public @ResponseBody void addStuff(@PathVariable("p1") String p1, @PathVariable("p2") String p2, @RequestParam(value = "value") String stuffValue) { 
     stuffService.addStuff(p1, p2, stuffValue); 
    } 

這按預期工作。然而,在瀏覽器的控制檯分析POST請求的URL的時候,我看到:

http://localhost:8080/my-project/stufflist/addStuff/p1/p2/file?value=my_giant_string_which_i_want_to_hide_from_this_url 

如何隱藏從POST請求的url這個PARAM?

回答

1
$http({ 
     url: 'stufflist/addStuff/' + p1 + '/' + p2, 
     method: "POST", 
     data: {'value': stuffValue} 
    }) 
    .then(function(response) { 
      // success 
    }, 
    function(response) { // optional 
      // failed 
    }); 

做這樣的事情,而不是使用$http.post

+1

它產生相同的結果... – Ricardo

+0

在控制檯中你看到這個或在URL? –

+0

Chrome控制檯和網絡開發面板 – Ricardo

0

這解決了這個問題。

$http({ 
      url: 'stufflist/addStuff/' + p1 + '/' + p2, 
      method: 'post', 
      data: $.param({value: stuffValue}), 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 

     }).then(function successCallback(response) { 

     }, function errorCallback(response) { 

     });