views:

472

answers:

2

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

A: 

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);
jax
Thanks! for your quick response.I'll try it and see if it solves my problem.
Kapil
It didn't solved my problem.But I have managed to solve my problem.Basic authentication was required in my case.Here's a link which could help(it helped me) :http://frontier.userland.com/stories/storyReader$2159
Kapil
A: 

this link id died. what was this article's name?

atasoyh