2013-05-10 2 views
5

Android 서버에 원격 서버에서 파일을 읽는 응용 프로그램이 있습니다. 파일 읽기 용 코드는 아래에 있습니다.Android에서 Microsoft ISA Server 인증

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

지금 모든 원격 파일은 파일에 액세스하기 위해 인증을 요구 프록시 (마이크로 소프트 ISA 서버) 뒤에 있습니다. 안드로이드에서 인증 매개 변수를 전달하여 파일에 액세스 할 수있는 방법을 알려주세요.

나는 다음과 같은 코드를 시도했지만 쓸모없는,

  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 내부 서버 오류를주고있다. 나는 또한 내가 작품을 할 수있다,

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

시도를 사용하여 내 경우에는 다음 링크를하지만 같은 오류 https://stackoverflow.com/a/10937857/67381

답변

1

을 시도했습니다.

P.

그것은 MS C# WebService를 응용 프로그램의 경우, ISA에 대한 아니지만, 어쩌면 ...

+0

나는 HTTP 얻고/1.1 500 (지정되지 않은 오류). – Siddiqui

+0

서버 로그? 여기서 예외일까요? –