AngularJs http 请求 header 没有改变
AngularJs http request header is not changing
我在尝试调用我的 WebApi 时遇到问题,我需要在请求中发送 header 授权凭据,但我没有收到。
我的请求 header 需要像我的 REST 测试人员
生成的请求 header 的这张图片
Authorization:Basic dXNlcm5hbWU6cGFzc3dvcmQ=
但是,当我尝试使用此代码块将其设置为 Angular 时
$http.defaults.headers.Authorization = 'Basic ' + credentials;
return $http.post('http://localhost:2703/api/Authenticate');
或者这个
return $http.post('http://localhost:2703/api/Authenticate', {
headers: { 'Authorization': 'Basic ' + credentials }
});
我的要求header变成了这个
Access-Control-Request-Headers: accept, authorization
有人可以告诉我我做错了什么吗?任何帮助将不胜感激。 :)
你可以这样做:
var header = {headers: {'Authorization': 'Basic ' + credentials}}
$http.post(url, payload, header)
.success(function (data) {
//stuff
}
我无法使用跨域请求解决我的问题,因此,我在同一域中配置了我的 Web Api 和 Web 应用程序。这样做,我可以正常更改 headers 并根据需要发送 post 请求。
我在尝试调用我的 WebApi 时遇到问题,我需要在请求中发送 header 授权凭据,但我没有收到。
我的请求 header 需要像我的 REST 测试人员
生成的请求 header 的这张图片Authorization:Basic dXNlcm5hbWU6cGFzc3dvcmQ=
但是,当我尝试使用此代码块将其设置为 Angular 时
$http.defaults.headers.Authorization = 'Basic ' + credentials;
return $http.post('http://localhost:2703/api/Authenticate');
或者这个
return $http.post('http://localhost:2703/api/Authenticate', {
headers: { 'Authorization': 'Basic ' + credentials }
});
我的要求header变成了这个
Access-Control-Request-Headers: accept, authorization
有人可以告诉我我做错了什么吗?任何帮助将不胜感激。 :)
你可以这样做:
var header = {headers: {'Authorization': 'Basic ' + credentials}}
$http.post(url, payload, header)
.success(function (data) {
//stuff
}
我无法使用跨域请求解决我的问题,因此,我在同一域中配置了我的 Web Api 和 Web 应用程序。这样做,我可以正常更改 headers 并根据需要发送 post 请求。