How to read the Location header from a POST API in angularjs?

后端 未结 2 1942
既然无缘
既然无缘 2020-12-19 01:12

My post method is something like this:

    public HttpResponseMessage AddUser(User user)
    {
        UserManager userManager = new UserManager();
        t         


        
2条回答
  •  囚心锁ツ
    2020-12-19 02:06

    Since .success() is deprecated in $http and has been replaced with .then() the update to this answer is to call header directly on the response that is injected into the promise.

    $http.post('http://localhost:30028/api/values/adduser', user)
        .then(function (response) {
            alert(angular.toJson(response.headers));
            //or
            alert(response.headers('Location'));
     });
    

提交回复
热议问题