tags:

views:

140

answers:

3

Hi,

I'm trying to do basic authentication to view a protected url. I want to access the protected url which looks like this:

http://api.test.com/userinfo/vid?=1234

So I do the following with a WebView:

mWebView.setHttpAuthUsernamePassword("api.test.com", "", "[email protected]", "mypassword");
mWebView.loadUrl("http://api.test.com/userinfo/user?uid=53461");

but the authentication doesn't seem to work, I'm just getting an output error page. Am I using the WebView method correctly here?

Update: Trying with curl:

curl -u [email protected]:mypassword http://api.test.com/userinfo/user?uid=53461

and it pulls the page fine. I tried every combination of the host parameter, the owners of the api don't know what I mean by 'realm' though (and neither do I) - what info could I give them to help this along?

Thanks

A: 

You may need something other than "" for the second parameter. Contact the developer of the Web site and find out what an appropriate realm should be. Or, use tools like curl to find out what the realm should be.

CommonsWare
Ok so I tried with curl and it works fine when supplying just username + password - udpated the Q, not sure why it still doesn't want to work?
A: 

In this example realm is By Invitation Only

AuthType Basic
AuthName "By Invitation Only"
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen sungo
Pentium10
Hi Pentium, where are you getting this example from though?
The AuthName directive sets the Realm to be used in the authentication. The realm serves two major functions. First, the client often presents this information to the user as part of the password dialog box. Second, it is used by the client to determine what password to send for a given authenticated area. http://httpd.apache.org/docs/2.0/howto/auth.html
Pentium10
A: 

Another option is to use a WebViewClient;

webview.setWebViewClient(new MyWebViewClient ());

private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedHttpAuthRequest(WebView view,
        HttpAuthHandler handler, String host, String realm) {

    handler.proceed("[email protected]", "mypassword");

}
}
dparnas