尝试使用HttpClient的获得多米诺HTTP会话

编程入门 行业动态 更新时间:2024-10-14 12:23:49
本文介绍了尝试使用HttpClient的获得多米诺HTTP会话 - 响应code是始终200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的Domino Sever的启用会话认证和HTTP端口号设置为8080。

当我执行下面的程序,以获得一个多米诺骨牌HTTP会话我总是得到下面放出来。

我知道响应code 200表示运行平稳。但我看不出在服务器上创建的任何HTTP会话。即使我提供错误的凭据UsernamePasswordCredentials(XXXXX,XXXXX)还是它返回200作为它的响应code。在这个有什么建议?

公共类ClientAuthentication {   公共静态无效的主要(字串[] args){          DefaultHttpClient的HttpClient =新DefaultHttpClient();             尝试 {                 httpclient.getCredentialsProvider()。setCredentials方法(新AuthScope(10.40.xx.xx,8080),                                                                         新UsernamePasswordCredentials(XXXXX,XXXXX));                 HttpPost httppost =新HttpPost(?HTTP://10.40.xx.xx:8080 / NAMES.NSF登录);                 的System.out.println(执行请求+ httppost.getRequestLine());                 HTT presponse响应= httpclient.execute(httppost);                 HttpEntity实体= response.getEntity();                 如果(response.getStatusLine()的getStatus code()== HttpURLConnection.HTTP_OK){                     的System.out.println(---------------还好还好------------------------- );                      的System.out.println(响应code+ response.getStatusLine()的getStatus code());                 }                 如果(实体!= NULL){                     的System.out.println(响应内容长度:+ entity.getContentLength());                 }             }赶上(例外五){                 // TODO自动生成的catch块                 e.printStackTrace();             }   } }

OUTPUT:

执行requestPOST HTTP://10.40.xx.xx:?8080 / NAMES.NSF登录HTTP / 1.1 - - - - - - - -好吧好吧 - - - - - - - - - - - - - 响应code 200 回应内容长度:4256

解决方案

您都设置了会话验证。但你正试图通过默认getCredentialsProvider做基本的身份验证。 200回应你得到的是实际的会话认证登录表单,你都应该职。

正确的顺序是

  • 请一个GET与您登录到
  • 数据库的URL
  • 与服务器的登录表单作为响应接收200
  • 在用户名和密码的名称/值对表单数据填写,并张贴

从理论上讲,你应该写自己的类实现针对Domino会话的认证形式CredentialsProvider接口,并使用它以简洁地实现这个seuqence延长AbstractHttpClient自己DominoHttpClient类;但我不认为这是值得的努力。

MY Domino Sever is enabled for Session Authentication and the HTTP Port number is configured to 8080.

When I execute the below program to obtain a domino HTTP session I always get the below out put.

I know RESPONSE CODE 200 indicates smooth operation. But I don't see any HTTP session created on the server. Even if I provide wrong credentials to the UsernamePasswordCredentials("xxxxx", "xxxxx") still it is returning 200 as its response code. Any suggestions on this ?

public class ClientAuthentication { public static void main(String[] args) { DefaultHttpClient httpclient = new DefaultHttpClient(); try { httpclient.getCredentialsProvider().setCredentials( new AuthScope("10.40.xx.xx", 8080), new UsernamePasswordCredentials("xxxxx", "xxxxx")); HttpPost httppost = new HttpPost("10.40.xx.xx:8080/names.nsf?Login"); System.out.println("executing request" + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK){ System.out.println("---------------OKAY OKAY-------------------------"); System.out.println("RESPONSE CODE " + response.getStatusLine().getStatusCode()); } if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

OUTPUT :

executing requestPOST 10.40.xx.xx:8080/names.nsf?Login HTTP/1.1 ---------------OKAY OKAY------------------------- RESPONSE CODE 200 Response content length: 4256

解决方案

You are set up for session authentication. but you are attempting to do basic authentication via the default getCredentialsProvider. The 200 response that you are getting is the actual session authentication login form, which you are supposed to POST.

The proper sequence is

  • Do a GET with the URL of the database you are logging into
  • Receive 200 with the server's login form as the response
  • Fill in the username and password name/value pairs for the form data and POST it

Theoretically you should write your own class that implements the CredentialsProvider interface tailored to the Domino session authentication form, and use it with your own DominoHttpClient class extending AbstractHttpClient in order to implement this seuqence cleanly; but I don't think it's really worth that effort.

更多推荐

尝试使用HttpClient的获得多米诺HTTP会话

本文发布于:2023-11-29 11:47:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多米诺   HttpClient   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!