当前位置: 首页 > 知识库问答 >
问题:

基本身份验证登录错误(406不可接受)

桂和同
2023-03-14

在为我的泽西REST服务实施基本身份验证后,我正在使用HTTPBasicAuthFilter为我的客户端API实施身份验证。我正在使用Glassfish 3.1.2和NetBeans。

我遵循了http://javaevangelist.blogspot.pt/2012/07/jax-rs-tip-of-day-basic-client_27.html,只更改了以下参数:

<代码>erc。setUsernamePassword(“blive2”,“microio”)-这是正确的登录

private static final String BASE_URI = "http://localhost:8080/LULServices/webresources"

webResource = client.resource(BASE_URI).path("entities.user")

因此,当我运行此文件时,将显示以下消息:

    Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client out-bound request
1 > GET http://localhost:8080/LULServices/webresources/entities.user
1 > Accept: text/plain
1 > Authorization: Basic YmxpdmUyOm1pY3JvaW8=

Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 406
1 < Date: Mon, 11 Mar 2013 17:30:38 GMT
1 < Content-Length: 1231
1 < Expires: Thu, 01 Jan 1970 01:00:00 GMT
1 < Content-Type: text/html
1 < Server: GlassFish Server Open Source Edition 3.1.2.2
1 < X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
1 < Cache-Control: no-cache
1 < Pragma: No-cache
1 < 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>GlassFish Server Open Source Edition 3.1.2.2 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 406 - Not Acceptable</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Not Acceptable</p><p><b>description</b>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers (Not Acceptable).</p><hr/><h3>GlassFish Server Open Source Edition 3.1.2.2</h3></body></html>

Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/LULServices/webresources/entities.user returned a response status of 406 Not Acceptable
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
    at lulClient.BasicAuthenticationClient$ExampleResourceClient.getMessage(BasicAuthenticationClient.java:38)
    at lulClient.BasicAuthenticationClient.main(BasicAuthenticationClient.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

因此,出现的是406不可接受。你能帮我解决这个问题吗?

谢谢

共有1个答案

关飞翼
2023-03-14

问题解决了。我向服务请求的信息只是以两种类型返回:APPLICATION_JSON或APPLICATION_XML。所以我必须将插入类型的代码部分更改为:

javax。ws。rs.core。MediaType。APPLICATION\u JSON或javax。ws。rs.core。MediaType。APPLICATION\u XML。

 类似资料:
  • 我正在进行多重身份验证。我的前端有一个带有卡号和密码的登录表单。在auth.php中 在route.php中 在logincontroller中, 在loginModel.php中 当我尝试登录时,我收到此错误 EloquentUserProvider.php第110行中的错误异常:传递给Illumate\Auth\EloquentUserProvider的参数1::validateCreenti

  • 我所期望的是:当用户从表单登录时,它可以调用restful服务,而无需经过基本身份验证(因为它已经经过身份验证)。我的想法是,角色为'role_user'的用户也应该调用restful服务。但是,当我从表单登录后,我也被提示进行基本身份验证,试图从浏览器调用restful服务。 有没有得到我所期望的?

  • 使用,https://github.com/firebase/FirebaseUI-Android/tree/master/codelabs/chat作为登录的参考,我在键入时似乎遇到了问题 我只能键入Auth的提供者,而不能键入,为什么会这样,它提示我键入社会提供者。

  • 问题内容: 从HttpClient 4.3开始,我一直在使用HttpClientBuilder。我正在连接到具有基本身份验证的REST服务。我将凭据设置如下: 但是,这不起作用(我正在使用的REST服务返回401)。怎么了? 问题答案: 从此处的 抢先身份验证 文档中: http://hc.apache.org/httpcomponents-client- ga/tutorial/html/aut

  • 我正在开发一个Laravel身份验证系统,当注册生效时,用户会登录,并在数据库中创建条目,但登录不起任何作用。我已经包括了谷歌硬盘上压缩的Laravel项目文件夹,因此如果您设置自己的数据库,您可以直接查看服务器配置不足的任何潜在原因。注意,这个问题在我添加jquerymobile之前就存在了,所以它不是AJAX负载。 https://drive.google.com/file/d/0BzXcUh

  • 在Laravel 5中,如果用户的基本身份验证失败,则返回的默认消息是“无效凭据”错误字符串。出现这种情况时,我试图返回一个自定义JSON错误。 我可以在vendor/laravel/framework/src/illumb/Auth/SessionGuard.php中编辑返回的响应,但是我还没有看到可以在vendor目录之外的何处更改此消息的行为。有办法吗? 看起来有一些方法可以通过Larave