如何将标头添加到$ http.post

时间:2017-09-12 06:08:47

标签: angularjs twitter-bootstrap angular-ui-bootstrap typeahead

我有以下用于bootstrap typeahead的代码。

return $http.post(searchClients, {
      params: {
            clientName: val,
     }
}).then(function(response){
    return response.data.results;
   });

我需要在标题中添加一个标记。 如何将标记添加到标题?

searchClients包含在其他位置定义的URL。 这段代码有效,我只需要知道如何在标题中添加一些额外的信息。

1 个答案:

答案 0 :(得分:1)

    $http({
    method: 'POST',
     headers: {
        'Content-Type': 'application/json;charset=UTF-8',
         'X-TOKEN': '9AF4E2526279434180C7365EF86F6E77'
    },
    url: 'http://xxx/User/Validate?UserName='+username+'&Password='+password+,

    data: {username:username, password:password}
}).then(function successCallback(response) {
    console.log(response);
     var logininfo = (response);
     localStorage.setItem("user_info", JSON.stringify(logininfo));
     $state.go('home');
}, function errorCallback(response) {
     console.log(response)
    if(response.status = 401){ //
       $scope.showpopup1("Message","invaild Username && Password");
    }
});