2011-11-04 77 views
0

我需要我的服務,用戶名認證和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

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 ====== >>><?xml version =「1.0」encoding =「utf-8」?> soap:Receiver服務器無法處理請求。 --- >根級別的數據無效。第1行,第1位。

+0

@ Dr.nik我相信你不知道如何進行web服務調用?你同樣面臨着問題。 –