2012-05-10 1 views
0

私はウェブサービスで認証する必要がありますので、Example from hereを試しました。私は必要なすべてのパラメータと資格情報を渡しましたが、私が応答を印刷したときに失敗を受けました。私は私のブラウザでユーザー名とパスワードをテストして、それがうまく働いていますが、私はここで何が起こっているのかを理解するカント:ウェブサービスの認証

04-19 02:10:14.063: WARN/etAuthenticationHandler(1613): Authentication scheme ntlm not supported 
04-19 02:10:14.070: WARN/DefaultRequestDirector(1613): Authentication error: Unable to respond to any of these challenges: {ntlm=WWW-Authenticate: NTLM, negotiate=WWW-Authenticate: Negotiate} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): OK: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <html xmlns="http://www.w3.org/1999/xhtml"> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <head> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <title>401 - Unauthorized: Access is denied due to invalid credentials.</title> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <style type="text/css"> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <!-- 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): fieldset{padding:0 15px 10px 15px;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): h1{font-size:2.4em;margin:0;color:#FFF;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): h2{font-size:1.7em;margin:0;color:#CC0000;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): background-color:#555555;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): #content{margin:0 0 0 2%;position:relative;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): --> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): </style> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): </head> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <body> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <div id="header"><h1>Server Error</h1></div> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <div id="content"> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <div class="content-container"><fieldset> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): <h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): </fieldset></div> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): </div> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): </body> 
04-19 02:10:14.080: DEBUG/MY_APP_TAG(1613): </html> 

私のWebサービスはASP.NETで

logcate ::(Responce)を開発しています

コード:

String username = "uname"; 
     String host = "host"; 
     String password = "pass"; 

     String urlApiCall_FindAllRepositories = 
       "http://host:2003/VoyagerWebservice7.0.1/webservices.asmx/Naptan_GetStops_ForVoyager_FromSearch_Custom?SerachText=Easton"; 

     try { 
      HttpClient client = new DefaultHttpClient(); 

      AuthScope as = new AuthScope(host, 2003); 
      UsernamePasswordCredentials upc = new UsernamePasswordCredentials(
        username, password); 

      ((AbstractHttpClient) client).getCredentialsProvider() 
        .setCredentials(as, upc); 

      BasicHttpContext localContext = new BasicHttpContext(); 

      BasicScheme basicAuth = new BasicScheme(); 
      localContext.setAttribute("preemptive-auth", basicAuth); 

      HttpHost targetHost = new HttpHost(host, 2003, "http"); 

      HttpGet httpget = new HttpGet(urlApiCall_FindAllRepositories); 
      httpget.setHeader("Content-Type", "text/xml"); 

      HttpResponse response = client.execute(targetHost, httpget, 
        localContext); 

      HttpEntity entity = response.getEntity(); 
      Object content = EntityUtils.toString(entity); 

      Log.d("MY_APP_TAG", "OK: " + content.toString()); 


     } catch (Exception e) { 
      e.printStackTrace(); 
      Log.d("MY_APP_TAG", "Error: " + e.getMessage()); 
     } 

答えて

1

あなたがどことして、HTTP認証を使用するに言及することを投稿サーバーはNTLM認証を使用しているようです。 NTLM認証にはNTCredentialsを使用する必要があります。

古いデバイスに問題がある場合は、http://code.google.com/p/android/issues/detail?id=4962#c274をご覧ください。

+0

古いデバイスをチェックしていないエミュレータでチェックしています –

関連する問題