androidauthenticationhttpclientisaserver

Authentication against ISA Server, Using HttpClient (Android)


I am developing a Android app, which communicates with a RESTful WCF Web Service in my server.
By using HttpClient, the application can read the json code from a url link.
For Example:

http://www.example.com/WebService/Service.svc/subscriptions/tiganeus
returns {"JSONUserDataResult":["Application A","Application B"]}

However, this web service itself is anonymous accessible, but protected by ISA Server.
Browser automatically shows "Authentication Required" dialog when this link is accessed externally. Simply fill in the username and password is OK.

I figured out how to do authentication in a webview. The following code works

private class MyWebViewClient extends WebViewClient {
    @Override
    public void onReceivedHttpAuthRequest(WebView view,
            HttpAuthHandler handler, String host, String realm) {
        handler.proceed("username", "password");
        System.out.println("httpa");
    }
}

But what I really need is to read the JSON code from the url. I have chosen to use HttpClient to do the job, but I can't figure out how to authenicate within the HttpClient. It sounds simple as any browser can do it.

Any help will be appreciated.


Solution

  • Apparently it is much simpler than I thought.

    DefaultHttpClient() httpClient = new DefaultHttpClient();       
    
    httpClient.getCredentialsProvider().setCredentials(
        AuthScope.ANY,
        new NTCredentials(user, pass, "tamtam", "tamtam"));         
    
    URI uri = new URI("http://www.example.com/WebService/Service.svc/subscriptions/tiganeus");
    HttpGet httpget = new HttpGet(uri);
    httpget.setHeader("Content-type", "application/json; charset=utf-8");*/
    
    HttpResponse response = httpClient.execute(httpget);
    
    HttpEntity responseEntity = response.getEntity();
    String result = EntityUtils.toString(responseEntity);
    

    httpClient.getCredentialsProvider().setCredentials works fine for the authentification through isa server (at least for in the way my isa-server is configured.

    It handles basic authentication as well.