开发者

Authentication Problem in Android

I have to send requests to a server in xml format.I did this using DefaultHttpClient and HttpPost(i have 开发者_如何转开发to do post request) using StringEntity to send the xml request but i got "401 Authorisation required" errror.I searched and i found out that authentication is required(i have username and password),but how to do is a problem for me.Currently, i am using "UsernamePasswordCredentials" and "BasicCredentialsProvider" but it throws "ClientProtocolException".I am not able to figure out what is wrong? Also, i have read that authentication are of different types-basic and digest.How do i know what my server supports? And how to implement them in Android.I am very new to this stuff,please help.!

Thanks


This is how I POST...no authentication is required

        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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜