如何使用基本身份验证从angularjs调用rest服务 [英] How to call rest service from angularjs with basic authentication

查看:129
本文介绍了如何使用基本身份验证从angularjs调用rest服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上运行了一个REST服务。



我有Chrome Postman使用基本身份验证访问该服务,我可以使用此帖子访问该服务。



但是,现在我想创建一个UI来显示AngularJS中来自REST的接收数据。



如何使用带有基本身份验证的AngularJS来调用此REST服务?

我有用户名和密码。



谢谢,

Ashok



我尝试过:



这是我试过的,但不知道如何传递基本身份验证凭据



函数getDataByAjax($ scope,$ http,url){

$ http.get(url)。

成功(功能(数据){

$ scope.greeting = data;

})。

错误(函数(数据,状态,标题,配置){

调试器;

alert(erro );

});

}

解决方案

范围,


http,url){

http.get(url)。

成功(函数(数据){


I have a REST service running on server.

I have Chrome Postman to access that service with Basic Authentication, and I can access that service with this Post man.

But, now I want to create a UI to show received data from REST in AngularJS.

How I can call this REST service by using AngularJS with Basic Authentication?
I have username and password.

Thanks,
Ashok

What I have tried:

This is what I tried, but dont know how to pass Basic Authentication credentials

function getDataByAjax($scope, $http, url) {
$http.get(url).
success(function (data) {
$scope.greeting = data;
}).
error(function (data, status, headers, config) {
debugger;
alert("erro");
});
}

解决方案

scope,


http, url) {


http.get(url).
success(function (data) {


这篇关于如何使用基本身份验证从angularjs调用rest服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆