标签: http-status-code-401

403 Forbidden vs 401 Unauthorized HTTP响应

对于存在的网页,但对于没有足够权限的用户(他们未登录或不属于正确的用户组),要提供的正确HTTP响应是什么?401?403?别的什么?到目前为止,我对每个人的看法都不太清楚.哪些用例适合每个响应?

http-status-codes http-response-codes http-headers http-status-code-403 http-status-code-401

2544
推荐指数
18
解决办法
97万
查看次数

如何使用jQuery获取HTTP状态代码?

我想检查页面是否返回状态代码401.这可能吗?

这是我的尝试,但它只返回0.

$.ajax({
    url: "http://my-ip/test/test.php",
    data: {},
    complete: function(xhr, statusText){
    alert(xhr.status); 
    }
});
Run Code Online (Sandbox Code Playgroud)

ajax jquery xmlhttprequest http-status-codes http-status-code-401

66
推荐指数
6
解决办法
16万
查看次数

401 Unauthorized:由于凭据无效,访问被拒绝

我正在使用IIS Express来部署MVC4应用程序.该网站在同一台计算机上运行完美.但在Lan,它给了我错误401.

<authentication mode="Forms">
    <forms loginUrl="~/" slidingExpiration="true" timeout="20">
    </forms>
</authentication>
Run Code Online (Sandbox Code Playgroud)

在家庭控制器

[HttpPost]
[AllowAnonymous]        
public ActionResult Index(LoginModel model, string returnUrl)
{
}
Run Code Online (Sandbox Code Playgroud)

我在管理员模式下从命令提示符启动IIS服务器.IIS以错误响应请求401.

任何线索?

iis asp.net-mvc http-status-code-401 form-authentication

66
推荐指数
6
解决办法
13万
查看次数

无法通过本地IIS获取Windows身份验证

所以我使用Intranet模板创建了一个新的ASP.NET MVC项目.web.config包含适当的值(例如<authentication mode="windows"/>).

如果我使用VS网络服务器启动Web应用程序,它看起来都很好 - 页面显示我的Windows域和用户名以及所有内容.但是,这适用于Opera和Safari以及IE和FF,它告诉我它根本不使用Windows身份验证(因为据我所知,这在除IE/FF之外的任何浏览器中都不起作用).

下一步是通过本地IIS使其工作.我创建一个指向www.mysite.mydomain到127.0.0.1的hosts文件条目.因此,在IIS中,我创建了一个绑定到www.mysite.mydomain的网站,并启用Windows身份验证并禁用匿名身份验证.

我已设置IE和FF以启用Windows身份验证,如下所示:

IE

  1. 将URL添加到Intranet组
  2. 确保在高级设置中启用了Windows身份验证

FF

将"www.mysite.mydomain"放入network.automatic-ntlm-auth.trusted-uris配置设置.

但是当我在IE/FF中拨打www.mysite.mydomain时,我会收到登录提示.有趣的是,即使我在这里输入我的Windows登录信息,它仍然会失败并再次向我显示登录提示.

我们这里没有活动目录,但我的理解是它应该可以正常使用本地帐户.

我想不出我需要做的任何其他事情.有什么建议?

编辑:我们最近切换到使用Active Directory,问题仍然存在.

编辑:当我取消登录提示时,我将进入"IIS 7.5详细错误"页面,其中包含以下信息:

HTTP错误401.2 - 未经授权由于身份验证标头无效,您无权查看此页面.**

iis asp.net-mvc ntlm windows-authentication http-status-code-401

65
推荐指数
4
解决办法
7万
查看次数

使用OAuth令牌查看Vimeo私有视频

任何人都可以使用scribe在Vimeo API中提供帮助吗?我的目标是访问私人视频(我上传),而不必强迫用户输入密码(此过程应在后台完成).

从我的理解/从研究中推断是必要的:

  1. 使用oAuth协议并通过以下链接请求申请授权:

    https://vimeo.com/oauth/authorize?oauth_token=XXXX

    此操作成功执行,响应数据发送到回调URL,如:

    http://127.0.0.1:8001/XPTO.html?oauth_token=AUTH_TOKEN_EXAMPLE&oauth_verifier=VERIFIIER__EXAMPLE"

  2. 根据Brad Dougherty(Vimeo API Staff)的说法,可以做类似的事情

    如果您自己完成OAuth流程,则可以保存该令牌并使用该令牌进行调用.

我正在使用此代码:

service = new ServiceBuilder().provider(VimeoApi.class)
                .apiKey("API_KEY_EXAMPLE")
                .apiSecret("API_SECRET_EXAMPLE")
                .build();

OAuthRequest request = new OAuthRequest(Verb.GET,
        "http://vimeo.com/api/rest/v2?video_id=50305416");

request.addQuerystringParameter("format", "json");
request.addQuerystringParameter("method", "vimeo.videos.getInfo");

String oauth_verifier=VERIFIER__EXAMPLE;
Verifier verifier = new Verifier(oauth_verifier);

//I've tried differents combination to create this token
//I believe that my problem is HERE
//One unsuccessfully try: Token requestToken = service.getRequestToken();
Token requestToken = new Token(
        AUTH_TOKEN_EXAMPLE,
        API_SECRET_EXAMPLE);

Token token = service.getAccessToken(requestToken, verifier);

service.signRequest(token, request); 
Response response = request.send(); …
Run Code Online (Sandbox Code Playgroud)

java oauth vimeo scribe http-status-code-401

42
推荐指数
1
解决办法
3080
查看次数

RESTful HTTP API中的授权,401 WWW-Authenticate

我正在创建一个RESTful服务来为Web应用程序提供数据.我有两个相关的问题.

1.如何处理未经授权的请求?

我打算用以下代码回复请求:

  • 资源是否打开并找到?200好的
  • 您是否需要通过身份验证才能访问资源?401未经授权
  • 您是否可以访问某类资源?403禁止
  • 您是否可以访问某类资源,但不能访问此特定资源?404 Not Found阻止人们了解他们无法访问的资源的存在.
  • 资源不存在吗?404未找到

这是RESTful服务的推荐方式吗?

2. WWW-Authenticate401响应应该提供什么标题?

我在维基百科上阅读(可能不是最准确的资源,但它对我有用)401响应必须包含一个WWW-Authenticate标题,但是在进一步搜索时我找不到任何资源说明这个值意味着什么以及它应该是什么.

我找到了几个有关此标题的SO问题和论坛主题,它们似乎都是关于OAuth的,建议不要使用401状态代码或者说你可以做些什么.

此标头应包含的正确值是什么?

rest http xmlhttprequest http-status-codes http-status-code-401

37
推荐指数
1
解决办法
3万
查看次数

GCM http 401授权错误

当我的后端服务器向GCM服务器发送post请求时,我收到HTTP 401的授权错误.

我按照这里描述的步骤:

http://developer.android.com/google/gcm/http.html#auth_error

>> api_key=AIzaSyDEy3...

>> curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send  -d "{\"registration_id\":\"ABC\"}"
Run Code Online (Sandbox Code Playgroud)

我明白了:

<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)

在故障排除中它说:

Authentication Error
The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
    1. Authorization header missing or with invalid syntax.
    2. Invalid project number sent as key.
    3. Key valid but with GCM service disabled.
    4. Request originated from a server not …
Run Code Online (Sandbox Code Playgroud)

android push-notification http-status-code-401 google-cloud-messaging

36
推荐指数
6
解决办法
8万
查看次数

是否可以发送401 Unauthorized AND重定向(带位置)?

我想401 Unauthorized在某个地方发送AND重定向客户端.然而:

如果我这样做:

header('HTTP/1.1 401 Unauthorized');
header('Location: /');
Run Code Online (Sandbox Code Playgroud)

服务器会发送一个302 Found带有Location,所以不是401 Unauthorized.

如果我这样做:

header('Location: /');
header('HTTP/1.1 401 Unauthorized');
Run Code Online (Sandbox Code Playgroud)

浏览器接收a 401 Unauthorized和a Location,但不重定向.

(IE 9和Chrome 16的行为相同,所以我猜它是正确的)

也许我在滥用HTTP?我希望我的应用程序界面对所有客户端完全相同:文本浏览器,现代浏览器,API调用等.401 +响应文本将告诉API用户什么是什么.重定向对浏览器很有用.

有(好的)方式吗?

http-redirect http-headers http-status-code-401

35
推荐指数
3
解决办法
3万
查看次数

Spring RestTemplate调用带有错误的webservice并分析状态代码

如果请求参数正常,我设计了一个web服务来执行任务,如果请求参数错误或为空,我会返回401 Unauthorized HTTP状态代码.

我正在使用RestTemplate执行测试,如果webservice成功回复,我就能验证HTTP 200 OK状态.但是,我无法测试HTTP 401错误,因为RestTemplate它本身会抛出异常.

我的测试方法是

@Test
public void testUnauthorized()
{
    Map<String, Object> params = new HashMap<String, Object>();
    ResponseEntity response = restTemplate.postForEntity(url, params, Map.class);
    Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
    Assert.assertNotNull(response.getBody());
}
Run Code Online (Sandbox Code Playgroud)

异常日志是

org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:88)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:533)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:489)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:318)
Run Code Online (Sandbox Code Playgroud)

我如何测试webservice是否回复了HTTP状态码401?

rest spring-mvc http-status-code-401 resttemplate

30
推荐指数
4
解决办法
5万
查看次数

Angular.js $ http.post TypeError:无法读取未定义的属性"data"

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

28
推荐指数
1
解决办法
3万
查看次数