如何在angularjs中使用POST

时间:2017-03-15 10:27:42

标签: angularjs postman

我在Google Chrome中使用Postman扩展来获取JSON数据。当我传入一个url并使用POST并提供api密钥的密钥授权和值时,我将获得JSON数据。我想通过角度来做同样的事情,所以我可以使用JSON数据并在我的视图中显示它。

我是角色新手,不知道如何使用POST方法。

1 个答案:

答案 0 :(得分:1)

您可以这样做:

$http.post(url, postData,
{
    withCredentials: true,
    headers:{ 'Authorization': 'Basic' + token} //you add all your headers
}
).then(function(response){ 
   // here you treat your response
  }, function(error){ 
   // here you treat your error 
  }
);