angularjs - 使用邮递员时,身份验证标头在 Angular 1.1.x 到 1.5.x 版本中不起作用
问题描述
我的 Web API 2.-0 代码是 -
OnValidateClientAuthentication = async context =>
{
.......string clientId;
........string clientSecret;
........if (context.TryGetBasicCredentials(out clientId, out clientSecret))
........{
..................if (clientId == "client1" && clientSecret == "secretKey1")
................{
....................context.Validated();
................}
...........}
}
我在这里使用承载身份验证。现在我从角度调用这个-
尝试了两种方法-
方法1。
在模块配置中 -
app.config(['$httpProvider', function ($httpProvider)
{
$httpProvider.defaults.headers.common['Authorization'] = 'Basic ' + window.btoa("Client1:secretKey1");
}
方法2。
app.service('memberService', function ($http)
{
var headers =
{
'Access-Control-Allow-Origin': true,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization':'Basic ' + window.btoa("Client1:secretKey1")
}
this.GetTocken = function (data)
{
var response = $http({
method: "Post",
url: window.g_baseUrl + "accesstoken",
headers: headers
});
return response;
};
}
我尝试使用 Angular 1.1.x 到 1.5.x,但没有成功。谷歌告诉 HttpClient 类是完全的。设置授权标头后愚蠢,两个键:访问控制请求方法和访问控制请求标头正在增加,但没有名称为“授权”的键。从邮递员发送请求时,在请求标头中添加授权密钥。
解决方案
推荐阅读
- java - 在更新查询中忽略 createdBy 和 CreatedDate
- javascript - 将文件从 NWjs 桌面应用程序拖放到 ms Outlook 中作为附件
- maven - 如何在 Ubuntu 18.04 上将 sqlite-jdbc 添加到本地 maven?
- android - Kotlin ArrayIndexOutOfBoundsException
- excel - Excel 文件上传到 Sharepoint 进行协作,用户遇到很多问题
- java - NullPointerException & QuerySyntaxException
- java - 如何在Android中获取字符串数组的长度?
- python - 将新的币安套接字添加到套接字管理器时未收到消息
- mysql - 如何使用 typeorm 批量更新插入实体?
- pyspark - 如何使用已安装的软件包运行 PySpark?