本文介绍了尝试使用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("http://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 http://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会话 - 响应code是始终200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 00:21