【问题标题】:Microsoft ISA Server Authentication in AndroidAndroid 中的 Microsoft ISA 服务器身份验证
【发布时间】:2013-05-10 07:25:50
【问题描述】:

我在Android中有一个应用程序,我正在从远程服务器读取文件,读取文件的代码如下;

            URI uri = null;
            try {
                uri = new URI("http://192.168.1.116/Server1/Users.xml");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            HttpGet httpget = new HttpGet(uri);
            httpget.setHeader("Content-type", "application/json; charset=utf-8");
            httpget.setHeader("host", "192.168.1.116");

            HttpResponse response = null;
            try {
                response = httpClient.execute(httpget);

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            HttpEntity responseEntity = response.getEntity();
            String result = null;
            try {
                result = EntityUtils.toString(responseEntity);
                Log.d("SERVER1", result);
            } catch (ParseException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

现在所有远程文件都位于代理(Microsoft ISA 服务器)之后,该代理需要身份验证才能访问这些文件。请指导我如何从 android 传递身份验证参数以访问文件。

我尝试了以下代码但没用,

           URL uri = null;
            try {
                uri = new URI("http:// 192.168.1.116/CookieAuth.dll?Logon");
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }

             DefaultHttpClient httpclient = new DefaultHttpClient();
            httpclient.getCredentialsProvider()
                    .setCredentials(
                            AuthScope.ANY,
                            new NTCredentials(username, password, deviceIP,
                                    domainName));

            HttpPost httppost = new HttpPost(uri);
            httppost.setHeader("Content-type",
                    "application/x-www-form-urlencoded");
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("curl", "Z2FServer1/users.xmlZ2F"));
            params.add(new BasicNameValuePair("formdir", "3"));
            params.add(new BasicNameValuePair("username", "test"));
            params.add(new BasicNameValuePair("password", "test"));

            UrlEncodedFormEntity ent = null;
            try {
                ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            httppost.setEntity(ent);
            try {
                response = httpclient.execute(httppost);

                Log.i("Test", response.getStatusLine().toString());

                HttpEntity entity = response.getEntity();

                if (entity != null) {

                    InputStream instream = entity.getContent();
                    result = convertStreamToString(instream);
                    Log.d("ISA Server", result);

                    instream.close();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

但它给出了HTTP1.1 500 内部服务器错误。我也尝试了以下链接,但同样的错误 https://stackoverflow.com/a/10937857/67381

【问题讨论】:

    标签: java android security ntlm


    【解决方案1】:

    就我而言,我使用

    public static DefaultHttpClient getClient(String username, String password,
            Integer timeOut) {
        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, timeOut);
        HttpConnectionParams.setSoTimeout(httpParams, timeOut);
        DefaultHttpClient retHttpClient = new DefaultHttpClient(httpParams);
        if (username != null) {
            retHttpClient.getCredentialsProvider().setCredentials(
                    new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                    new UsernamePasswordCredentials(username, password));
        }
    
        return retHttpClient;
    }
    

    试一试,可能会成功。

    附言

    它不适用于 ISA,不适用于 MS C# WebService 应用程序,但也许...

    【讨论】:

    • 我收到 HTTP/1.1 500(未指定错误)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    相关资源
    最近更新 更多