其他分享
首页 > 其他分享> > Lotus Domino服务器上的Android HTTP认证

Lotus Domino服务器上的Android HTTP认证

作者:互联网

我正在开发一个能够从Lotus Domino数据库读取数据的android应用程序.
我开始创建一个页面来测试HTTP身份验证,但遇到了很多困难.这是我的代码段:

    public void GoAuth(View v){
    final String httpsURL = "http://xxx.xxx.xxx.xxx/names.nsf/mypage?openpage";
    final DefaultHttpClient client = new DefaultHttpClient();
    final HttpPost httppost = new HttpPost(httpsURL);

    String userName = "demo";
    String password = "demo";

    try {
        //authentication block:
        final List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
        nvps.add(new BasicNameValuePair("Username", userName));
        nvps.add(new BasicNameValuePair("Password", password));
        final UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
        httppost.setEntity(p_entity);

        //sending the request and retrieving the response:
        HttpResponse response = client.execute(httppost);
        HttpEntity responseEntity = response.getEntity();

        if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK){
            //handling the response 
            final InputSource inputSource = new InputSource(responseEntity.getContent());
            TextView res=(TextView)findViewById(R.id.result);
            res.setText("Server response: "+inputSource.toString());
        }

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

服务器响应为:
    org.xml.sax
    InputSource @ 40575700

在浏览器中尝试同样的操作,我看到登录页面,然后看到“ mypage”的内容.
对于在Android上必须遵循的正确方法和机制,我有些困惑.
任何帮助将不胜感激!

解决方法:

正如Richard在评论中提到的那样,您可能会看到“ session based authentication表格”,要处理任何类型的代码都相当麻烦.

为了获得“ HTTP基本身份验证”(可能是任何一种语言都可以轻松处理)(基于浏览器的用户名/密码提示),您可以/应该在服务器端实现Override Session Authentication Rule.

另请参见Domino 7.0.2 allows for overriding of session-based authentication

标签:lotus-domino,android
来源: https://codeday.me/bug/20191101/1983749.html