针对ISA Server身份验证,使用的HttpClient(Android版) [英] Authentication against ISA Server, Using HttpClient (Android)

查看:159
本文介绍了针对ISA Server身份验证,使用的HttpClient(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,它与一个RESTful WCF Web服务在我的服务器进行通信。结果
通过使用HttpClient的,应用程序可以读取URL链接的JSON code。结果
例如:

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/订阅/ tiganeus 结果
返回{JSONUserDataResult:应用程序A,应用程序B]}

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

不过,这个Web服务本身是匿名的访问,而是通过ISA服务器的保护。结果
当这条链路外部访问浏览器会自动显示需要验证对话框。只需在填写用户名和密码就可以了。结果

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.

我想出如何在网页视图做认证。下面code ++工程

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");
    }
}

但我真正需要的是读取URL中的JSON code。
我选择使用的HttpClient做工作,但我无法弄清楚如何HttpClient的内authenicate。这听起来很简单,任何浏览器可以做到这一点。

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.

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

显然,这比我想象的要简单得多。

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方法通过ISA Server的鉴别工作正常
(至少在方式我的ISA-服务器被配置

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.

这篇关于针对ISA Server身份验证,使用的HttpClient(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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