Nikunj Patel
Nikunj Patel

Reputation: 22076

Unable to authenticate services

i need to authenticate my services with username and passwor i have try this but not get sucess can you help me

when i print inlog cat i got ::

Update 3 ::

11-04 16:07:58.767: INFO/System.out(1531): Returned ======>>> <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">Server was unable to process request. ---&gt; Data at the root level is invalid. Line 1, position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

Code ::

   DefaultHttpClient UserIDclient = new DefaultHttpClient();
                 HttpPost httppost = new HttpPost(url);
                 List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
                 nvps.add(new BasicNameValuePair("username","password"));
                 UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps,HTTP.UTF_8);
                 httppost.setEntity(p_entity);
                 HttpResponse response = UserIDclient.execute(httppost);
                 HttpEntity resEntity = response.getEntity();
                    Returned = EntityUtils.toString(resEntity);
                    System.out.println("ans is :: "+ Returned);

            System.out.println("Returned ======>>> "+Returned);

Upvotes: 0

Views: 275

Answers (1)

Paresh Mayani
Paresh Mayani

Reputation: 128448

1st Thing:

Check whether the "returned" string is null or not.

2nd Thing:

One thing i notice that you have written below lines for twice, what is the need to call execute() method before passing username and password:

HttpResponse response = httpclient.execute(post);
HttpEntity entity = response.getEntity();
Returned = EntityUtils.toString(entity);

Instead your code should be:

HttpClient httpclient = new DefaultHttpClient();
         HttpPost post = new HttpPost(url);

 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        // Your DATA
        nameValuePairs.add(new BasicNameValuePair("ID", "username"));

        nameValuePairs.add(new BasicNameValuePair("Password", "password"));

        response.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                HTTP.UTF_8));
        HttpResponse response1 = httpclient.execute(post);

        if(response1.getStatusLine().getStatusCode()==200)
        {
            HttpEntity resEntity = response1.getEntity();
            System.out.println("=========> Response => "+iStream_to_String(resEntitiy.getContent()));  

        }

// You can get iStream_to_String from here.

Upvotes: 1

Related Questions