无法验证服务

问题描述:

我需要我的服务,用户名认证和passwor我有尝试this但没有得到sucess你可以帮我无法验证服务

当我打印inlog猫我得到::

更新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> 

代码::

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); 

1日的事情:

检查是否 “返回” 字符串为空或不是。

第二件事:

有一件事我注意到,你已经写了下面的两次行,什么是需要调用传递用户名和密码,然后execute()方法:

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

相反你的代码应该是:

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())); 

     } 

//你可以从here得到iStream_to_String。

+0

检查更新后的代码,运行它并只检查你在控制台得到的内容。 –

+0

11-04 15:46:38.347:INFO/System.out(1381):Returned ====== >>> soap:Receiver服务器无法处理请求。 --- >根级别的数据无效。第1行,第1位。 soap:Reason> soap:Envelope> –

+0

@ Dr.nik我相信你不知道如何进行web服务调用?你同样面临着问题。 –