2010-02-13 43 views
2

我將請求發送到一個XML格式的服務器format.I這樣做使用DefaultHttpClient和HttpPost(我必須做崗位要求)使用StringEntity發送XML請求,但我得到「401授權要求」 errror 。我搜查,我發現,認證要求(我的用戶名和密碼),而是如何做的是,我使用「UsernamePasswordCredentials」和「BasicCredentialsProvider」爲me.Currently一個問題,但它會拋出「ClientProtocolException」。我是無法弄清楚什麼是錯的?此外,我已閱讀,認證是不同類型的,基本的和digest.How做我知道我的服務器支持?而如何實現它們Android.I很新的這東西,請大家幫幫忙!身份驗證問題在Android中

感謝

回答

0

這是我的帖子...不需要身份驗證

 DefaultHttpClient hc=new DefaultHttpClient(); 
     ResponseHandler <String> res=new BasicResponseHandler(); 
     HttpPost postMethod=new HttpPost("http://mydomain.com/myfile.php"; 
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 


     //These are the values you are posting 

     nameValuePairs.add(new BasicNameValuePair("name", username.getText().toString()));  
     nameValuePairs.add(new BasicNameValuePair("username", username.getText().toString())); 
     nameValuePairs.add(new BasicNameValuePair("email", email.getText().toString())); 
     nameValuePairs.add(new BasicNameValuePair("password", password.getText().toString())); 

     postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
     String response=hc.execute(postMethod,res); 
+0

謝謝!爲了您的快速響應。我會嘗試一下,看看它是否能解決我的問題。 – Kapil 2010-02-14 06:06:12

+0

它並沒有解決我的問題。但我已成功地解決我的problem.Basic認證在我case.Here的鏈接被要求這將有助於(它幫助我): http://frontier.userland.com/stories/storyReader $ 2159號郵政編碼 – Kapil 2010-02-15 08:00:22