NTLM身份验证中的WebView [英] NTLM Authentication in a WebView

查看:244
本文介绍了NTLM身份验证中的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载它会显示在的WebView A图像的URL。 我需要传递的凭据(用户名和放大器;密码),加载的URL,然后

下面的网址是由具有NTLM身份验证的服务器托管。

我能再创这样的URL,并获取数据。但我怎么做同样的东西在Android的一个的WebView

解决方案

您可以使用奇尔卡特库了解NTLM身份验证。

  1. 下载Java类(包含在从下载部分的ZIP / RAR文件) 和包添加到/ src文件夹。包名是com.chilkatsoft
  2. 添加到库中/ libs文件夹。 奇尔卡特库文件夹为:

    • armeabi
    • armeabi-V7A
    • MIPS
    • 86

       公共类MainActivity延伸活动{
      保护无效的onCreate(包savedInstanceState){
          super.onCreate(savedInstanceState);
          的setContentView(R.layout.activity_main);
          布尔成功;
          成功= http.UnlockComponent(东西);
          如果(成功!= TRUE){
              返回;
          }
      
          http.put_Login(<用户名>中);
          http.put_Password(<密码>中);
          http.put_NtlmAuth(真正的);
          http.put_SessionLogFilename(ntlmAuthLog.txt);
          字符串的HTML;
          的HTML = http.quickGetStr(http://websitewithntlmnauthentication.com);
          //加载数据从字符串HTML一个web视图。
          webView.loadUrl(HTML代码,,UTF-8); }
       

      和之后添加此的onCreate()

       静态{
                //重要:确保传递给LoadLibrary名的共享库相匹配
                //在项目的库/ armeabi目录中找到。
                //为libchilkat.so,通过奇尔卡特给LoadLibrary
                //为libchilkatemail.so,通过chilkatemail给LoadLibrary
                //  等等。
                //
                的System.loadLibrary(奇尔卡特);
      
                //注意:如果不正确的库名传递到的System.loadLibrary,
                //然后你会看到在应用程序启动时出现以下错误信息:
                //应用程序<您的应用程序,名称>已意外停止,请重试。
            }
       

I am trying to load a URL which will show a image in a WebView. I need to pass the credentials (username & password) before loading the URL.

Here, the URL is hosted from a server which has NTLM authentication.

I am able to hit another such URL and get the data. But how do I do the same stuff for a WebView in Android?

解决方案

You can use the Chilkat Library for NTLM authentication.

  1. download the java classes (contained in the zip/rar file from the downloads section) and add the package to the /src folder. the package name is com.chilkatsoft
  2. add the libraries to the /libs folder. the chilkat libraries folder are:

    • armeabi
    • armeabi-v7a
    • mips
    • x86

      public class MainActivity extends Activity {
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          boolean success;
          success = http.UnlockComponent("anything");
          if (success != true) {
              return;
          }
      
          http.put_Login("<Username>");
          http.put_Password("<Password>");
          http.put_NtlmAuth(true);
          http.put_SessionLogFilename("ntlmAuthLog.txt");
          String html;
          html = http.quickGetStr("http://websitewithntlmnauthentication.com");
          //load the data to a webview from the string "html".
          webView.loadUrl(html,"","UTF-8"); }
      

      and add this after the onCreate():

      static {
                // Important: Make sure the name passed to loadLibrary matches the shared library
                // found in your project's libs/armeabi directory.
                //  for "libchilkat.so", pass "chilkat" to loadLibrary
                //  for "libchilkatemail.so", pass "chilkatemail" to loadLibrary
                //  etc.
                // 
                System.loadLibrary("chilkat");
      
                // Note: If the incorrect library name is passed to System.loadLibrary,
                // then you will see the following error message at application startup:
                //"The application <your-application-name> has stopped unexpectedly. Please try again."
            }
      

这篇关于NTLM身份验证中的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆