2017-09-13 63 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) { 

     });