6

認証を使用してWebサイトにアクセスしようと試みましたが、何が問題なのかわかりません。それぞれをリストします。誰かがこれを試し、それを機能させましたか?

これは、Java Androidプログラマーにとって理解するのが難しいことではなく、monodroid EDITを使用していることも問題ではありません(以下のJava実装は問題なく機能するため、問題ありません) ENDEDIT

WebViewを介してSSRSRDLにアクセスしようとしていますが、いくつかの一般的なクレデンシャルをプラグインする必要があります。

アクティビティ:

    public static string username = "...";
    public static string password = "...";
    public static string website  = "http://10.0.0.5/Reports";

    private WebView webView;

    private void setupWebView(int attempt)
    {
        webView.Settings.JavaScriptEnabled = true;
        webView.Settings.BlockNetworkLoads = false;

        switch (attempt)
        {
            case 1:
                {
                    webView.SetHttpAuthUsernamePassword(website, "", username, password);                                              
                }break;
            case 2:
                {
                    webView.SetWebViewClient(new AuthenticationClient(this));                        
                }break;
        }
        webView.LoadUrl(website);
    }

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        webView = new WebView(this);

        setupWebView(1);//1 or 2 depending on what I am testing

        // Set our view from the "main" layout resource
        SetContentView(webView);           
    }
}

AuthenticationClient:

    //DECLARED IN ANOTHER FILE
    [Android.Runtime.Register("android/webkit/WebViewClient", DoNotGenerateAcw = true)]
    public class AuthenticationClient:WebViewClient
    {
        private Context _context;

        public AuthenticationClient(Context context)
        {
            _context = context;
        }

        public override void OnReceivedError(WebView view, ClientError errorCode, string description, string failingUrl)
        {
            Toast.MakeText(_context, "OnReceivedError: " + errorCode, ToastLength.Long);
            //base.OnReceivedError(view, errorCode, description, failingUrl);
        }

        public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
        {
            Toast.MakeText(_context, "OnPageStarted: " + url, ToastLength.Long);
            //base.OnPageStarted(view, url, favicon);
        }

        public override bool ShouldOverrideUrlLoading(WebView view, string url)
        {
            Toast.MakeText(_context, "ShouldOverrideUrlLoading: " + url, ToastLength.Long);
            view.LoadUrl(url);
            return true;
        }

        public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm)
        {
            Toast.MakeText(_context, "OnReceivedHttpAuthRequest: " + host, ToastLength.Long);
            handler.Proceed(Activity1.username, Activity1.password);
        }
    }
    //END DECLARATION

試行1:ページを読み込もうとさえしません。エラーが発生し続けます:
chromium(18710):external / chromium / net / http / http_auth_gssapi_posix.cc:463:[0821/095922:WARNING:http_auth_gssapi_posix.cc(463)]互換性のあるGSSAPIライブラリが見つかりません

試行2:トーストメッセージを1つも表示しません。

私はすでに見ました:
http :
//developer.android.com/reference/android/webkit/WebView.html WebView setHttpAuthUsernamePasswordを使用していますか?
WebView.setHttpAuthUsernamePassword()が機能していませんか?
WebアプリケーションからSSRS2005レポートにユーザー名とパスワードを渡す

その他
の作業Javaで実行しましたが、正常に動作します。私はまだAndroid用のMonoソリューションが必要です:

public class Android_reporttestActivity extends Activity {
public static String username = "...";
public static String password = "...";
public static String website = "http://10.0.0.5/Reports";       

private WebView setupWebView()
{
    WebView webView = new WebView(this); 

    webView.setWebViewClient(
        new WebViewClient(){
            public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm)
            {                           
                handler.proceed(username,password);
            }
        }
    );

    return webView;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webview = setupWebView();

    // Set our view from the "main" layout resource
    setContentView(webview);

    webview.loadUrl(website);
}
4

1 に答える 1

2

以下を実行すると、すべてが期待どおりに機能します。

[Activity (Label = "WebViewExample", MainLauncher = true)]
public class Activity1 : Activity
{
    string url;
    WebView mWebView;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        url = "http://awebsite.com"; 
        mWebView = (WebView)FindViewById<WebView> (Resource.Id.webview);
        mWebView.SetWebViewClient (new ViewClient (this));
        mWebView.Settings.JavaScriptEnabled = (true);
        mWebView.Settings.PluginsEnabled = (true);
        mWebView.LoadUrl (url);
    }

    class ViewClient : WebViewClient
    {
        Activity1 _activity;

        public ViewClient(Activity1 activity)
        {
            _activity = activity;   
        }

        public override void OnPageStarted (WebView view, string url, Android.Graphics.Bitmap favicon)
        {
            Console.WriteLine ("On Page Started");
        }

        public override void OnReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, string host, string realm)
        {
            Console.WriteLine ("On received Http auth request");
            handler.Proceed("username", "password");
        }

        public override bool ShouldOverrideUrlLoading (WebView view, string url)
        {
            Console.WriteLine ("Should Override Url Loading...");
            return base.ShouldOverrideUrlLoading (view, url);
        }
    }
}

トーストが表示されない理由は、おそらく ".Show()" を呼び出していないため、トーストが表示されないためです。

それでも起動して実行できない場合は、ヒットに使用できる URL を提供すると非常に便利です。

これが役に立てば幸いです。

クリスNTR

于 2012-08-21T15:33:32.247 に答える