Angular.js v1.0.6
制作$ http.post并收到非200 resposne(在这种情况下为401)
$http.post('http://localhost:3030/auth/login', {
username: 'username',
password: 'password'
})
.success(function(data) {
// Gets called on a 200 response, but not on a 401
console.log('success');
})
.error(function(err) {
// Never gets called & dies with error described below.
console.log('error');
});
Run Code Online (Sandbox Code Playgroud)
Angular会抛出以下错误:
TypeError: Cannot read property 'data' of undefined
at http://localhost:9000/components/angular/angular.js:8891:22
at wrappedCallback (http://localhost:9000/components/angular/angular.js:6797:59)
at http://localhost:9000/components/angular/angular.js:6834:26
at Object.Scope.$eval (http://localhost:9000/components/angular/angular.js:8011:28)
at Object.Scope.$digest (http://localhost:9000/components/angular/angular.js:7876:25)
at Object.Scope.$apply (http://localhost:9000/components/angular/angular.js:8097:24)
at done (http://localhost:9000/components/angular/angular.js:9111:20)
at completeRequest (http://localhost:9000/components/angular/angular.js:9274:7)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost:9000/components/angular/angular.js:9244:11)
Run Code Online (Sandbox Code Playgroud)
并且从不调用.success()回调或错误.error()回复使得无法处理响应. …
javascript authentication http http-status-code-401 angularjs
当我尝试使用EWS API发送电子邮件时,出现以下错误:(in message.Send();)
请求失败.远程服务器返回错误:(401)未经授权.
我的代码如下:
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//WebService Uri
try
{
exchangeService.Url = new Uri("https://exchangeserver/ews/exchange.asmx");
}
catch (Exception ex)
{
throw new Exception(string.Format("WebService Uri:" + ex));
}
//Credentials
try
{
exchangeService.Credentials = new WebCredentials("user@domain", "pwd", "domain");
}
catch (Exception ex)
{
throw new Exception(string.Format("Credentials:" + ex));
}
//Send a mail
try
{
EmailMessage message = new EmailMessage(exchangeService);
message.Subject = "Test";
message.Body = "Test";
message.ToRecipients.Add("destination@domain");
message.Save();
message.Send();
}
catch (Exception ex)
{
throw ex;
}
Run Code Online (Sandbox Code Playgroud)
我在本网站上阅读了有关此问题的其他帖子,但他们无法解决我的问题.
c# exchange-server-2007 unauthorized exchangewebservices http-status-code-401
我正在努力从控制台应用程序访问Dynamics 2016 CRM OData Web API.
我们安装了Dynamics CRM 2016,配置了基于声明的身份验证,并使用AD FS v3.0.
我的理解是控制台应用程序(或Web应用程序)应该能够使用Windows集成身份验证(即NTML或Kerberos)访问Web API而无需任何特殊处理......或者OAuth流程在启用时可能会起作用.
对于访问Dynamics"pages"的常规用户,身份验证工作正常(重定向到AD FS登录页面),但访问OData API似乎不起作用(例如:https://crm.domain.org/api/发现/ v8.0 /):
我尝试过的事情:
如果我启用基于声明的身份验证,并通过PowerShell 激活OAuthAdd-PSSnapin Microsoft.Crm.PowerShell ; $ClaimsSettings = Get-CrmSetting -SettingType OAuthClaimsSettings; $ClaimsSettings.Enabled = $true ; Set-CrmSetting -Setting $ClaimsSettings ;.
Windows集成身份验证仍然不起作用,但现在可以使用承载身份验证.我可以使用此代码段检索OAuth端点以生成令牌,并用于AuthenticationContext.AcquireTokenAsync发出令牌,然后在AuthorizationHTTP Header中传递它...但是,无论如何,我都会收到此错误:
Bearer error=invalid_token, error_description
=Error during token validation!, authorization_uri=https://our.adfs.domain.org/adfs/oauth2/authorize, …
我有一个大型内部企业基于Web的应用程序在IIS6上运行ASP.NET 3.5的情况,生成401"未授权"响应,然后是200"Ok"响应(由Fiddler描述).我知道为什么会发生这种情况(集成auth强制浏览器重新发送凭据)但我正在寻找一些关于如何最小化或根除情况的想法.有问题的应用程序在WAN中运行,一些用户遇到的延迟时间高达250毫秒,因此强制后续请求会对页面加载时间产生明显影响,尤其是当页面上有许多级联下拉列表时.
应用程序的用户是托管桌面环境内部的,因此从部署的角度来看,可以强制浏览器在第一个请求上发送凭据(这是否可能?).这适用于需要用户身份但不需要身份验证的资源(WebResource.axd,ScriptResource.axd和一些自定义Web服务)的页面,允许匿名身份验证.我已经看过在web.config中基于每个位置定义这个,但是结果是混合的(仍然有许多401响应).
对于处理这种情况的"最佳实践",我很感激.有很多资源可以识别问题,但我找不到提供可行解决方案的资源.
谢谢!
编辑:可以通过向Web配置添加位置条目匿名请求不需要身份验证的资源(即用于级联下拉列表的Web服务),但我还没有找到经过身份验证的资源的答案.
我们正在从Google的GCM服务中获得间歇性的401未经授权的错误.在过去,它100%的时间都在工作.问题可能与我们的路由器接受IPv6流量一致,但即使我们在适配器上禁用IPv6,问题仍然存在.它也不适用于单独的IPv4网络.我们还使用Google建议的指数退避(http://developer.android.com/google/gcm/adv.html#retry)重试我们的请求,因此问题可能会随着时间的推移而发展,我们可能没有注意到.
我们测试的所有生产IPv4和IPv6地址都列在我们的项目中:https: //console.developers.google.com
这是我们的密钥看起来,我们已经列出了我们的整个可公开访问的子网进行测试,但我也尝试过只使用单个IP地址.

有时它有效:
C:\Users\Administrator>curl --header "Authorization: key=REDACTED" --header Content-Type:"application/json" https://android.googl
eapis.com/gcm/send -d "{\"registration_ids\":[\"test\"],\"data\":{\"code\":123}
}" -k
{"multicast_id":REDACTED,"success":0,"failure":1,"canonical_ids":0,"r
esults":[{"error":"InvalidRegistration"}]}
Run Code Online (Sandbox Code Playgroud)
但是,有时我们得到这样的回应:
C:\Users\Administrator>curl --header "Authorization: key=REDACTED" --header Content-Type:"application/json" https://android.googl
eapis.com/gcm/send -d "{\"registration_ids\":[\"test\"],\"data\":{\"code\":123}
}" -k
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)
次要更新(2014年4月4日)
将设置更改为"允许任何IP"可以解决问题,但更改为任何其他IP地址会再次破坏它.
android unauthorized http-status-code-401 google-cloud-messaging
我正在与AngularJS建立一个与服务(JAVA)通信的SPA.
当用户发送他的用户名/密码时,服务会发回两个:访问令牌和刷新令牌.我正在尝试处理:如果我得到状态401的响应,则发送回刷新令牌,然后再次发送您的最后一个请求.我尝试使用包含$ http来做到这一点,但angular不允许我将它包含在这个拦截器中.有没有办法用我收到的响应参数重新创建原始请求?
就像是:
在错误重定向到/登录页面
'use strict';
angular.module('testApp')
.factory('authentificationFactory', function($rootScope, $q, $window, $location, CONF) {
return {
request: function(config) {
config.headers = config.headers || {};
if ($window.sessionStorage.token) {
config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
}
console.log(config);
$rootScope.lastRequest = config;
return config;
},
response: function(response) {
console.log($rootScope.lastRequest);
if (response.status === 401) {
if ($window.sessionStorage.refreshToken) {
//Save, request new token, send old response
//if it fails, go to login
$location.url('/login');
} else {
$location.url('/login');
}
}
return response …Run Code Online (Sandbox Code Playgroud)javascript authentication http-status-code-401 access-token angularjs
我正在尝试将github问题api集成到一个项目中.我想我遵守了oauth的规则,以及http://develop.github.com/p/issues.html上需要和提到的所有内容,但它似乎不起作用.我没有收到详细的错误消息,只有401.
用django,python实际实现:
url = 'https://github.com/login/oauth/access_token?client_id=%(client_id)s&redirect_uri=%(redirect_uri)s&client_secret=%(client_secret)s&code=%(code)s' % locals()
req = urllib2.Request(url)
response = urllib2.urlopen(req).read()
access_token = re.search(r'access_token=(\w+)', response).group(1)
url = 'http://github.com/api/v2/json/issues/open/%(user)s/%(repo)s' % locals()
params = urllib.urlencode({'login': user, 'token': access_token, 'title': 'title', 'body': 'body'})
req = urllib2.Request(url, params)
try:
response = urllib2.urlopen(req)
except HTTPError, e:
return HttpResponse('[*] Its a fckin %d' % e.code)
except URLError, …Run Code Online (Sandbox Code Playgroud) 我想允许访问Anonymous.aspx所有用户的页面,我已将基本身份验证设置为已启用,并将连接设置为特定用户.
我的问题是在尝试访问时http://MyIPAddress/MyAlias/Anonymous.aspx,出现了身份验证弹出窗口 - 理想情况下它不应该出现,当我关闭弹出窗口时,得到401.2 Unauthorized error- 这很明显
错误摘要
HTTP错误401.2 - 未经授权由于身份验证标头无效,您无权查看此页面.错误代码0x80070005
下面是我的web.config文件的快照.
<configuration>
<system.web>
<authentication mode=“Windows“/>
</system.web>
<location path=“Anonymous.aspx“>
<system.web>
<authorization>
<allow users=“*“/>
</authorization>
</system.web>
</location>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误.
basic-authentication iis-7.5 unauthorizedaccessexcepti http-status-code-401
经过大量的谷歌搜索和Stackoverflowing,我仍然不清楚,因为许多文章和问题/答案太笼统(包括403 Forbidden vs 401 Unauthorized HTTP响应,这不是专门针对我的用例).
问题:当用户未登录并请求查看仅应向登录用户显示的某些页面时,正确的HTTP状态代码是什么?
我有许多ajax动作的应用程序(使用JQuery.ajax实现),它返回JSON ot html.其中一些应该只有授权用户才能访问,我用[Authorize]属性修饰它们.对于非ajax操作,如果用户未被授权 - 系统将其重定向到登录页面(在web.config中配置).
但是这不适用于ajax操作,因为如果用户被授权 - 他加载页面,在cookie过期后他没有被授权,而不是html块,它应该替换旧的,他在块内得到我的登录页面.
我知道我可以手动解决这个问题,例如删除[Authorize]属性,如果用户没有授权,则返回特殊的json/empty html.但我不喜欢这个解决方案,因为我需要重写我的所有动作和ajax函数.我想要全局解决方案,允许我不要重写我的操作(可能是自定义授权属性,或某些http未经授权的结果自定义处理).
我想返回状态代码,如果请求是ajax,并且重定向到登录页面,如果请求不是ajax.
asp.net-mvc jquery unauthorized http-status-code-401 asp.net-mvc-3
unauthorized ×3
angularjs ×2
javascript ×2
access-token ×1
adfs3.0 ×1
android ×1
asp.net-mvc ×1
c# ×1
django ×1
github-api ×1
http ×1
iis-7.5 ×1
jquery ×1
oauth ×1
python ×1