2011-09-27 144 views
0

我有一個問題,我打電話給谷歌瀏覽器RESTClient插件軟件上運行的Web服務,並給出了200響應,但是當我在我的Android應用程序中調用相同時,它沒有響應。Web服務沒有響應

我不知道Android的問題是什麼。請爲我提供正確的結果。

感謝

錯誤堆棧

09-27 10:41:14.582: INFO/System.out(373): <HTML><TITLE>404 Not Found</TITLE><BODY><H1>404 Not Found</H1><P>Unable to connect to host</BODY></HTML> 
09-27 10:41:14.582: WARN/System.err(373): org.json.JSONException: Value <HTML><TITLE>404 of type java.lang.String cannot be converted to JSONObject 
09-27 10:41:14.582: WARN/System.err(373):  at org.json.JSON.typeMismatch(JSON.java:107) 
09-27 10:41:14.582: WARN/System.err(373):  at org.json.JSONObject.<init>(JSONObject.java:158) 
09-27 10:41:14.582: WARN/System.err(373):  at org.json.JSONObject.<init>(JSONObject.java:171) 
09-27 10:41:14.582: WARN/System.err(373):  at com.equinix.android.parsing.Parse_Json.parse_ShowOrders(Parse_Json.java:323) 
09-27 10:41:14.582: WARN/System.err(373):  at com.equinix.android.showmyorders.ShowMyOrders$2.run(ShowMyOrders.java:112) 

代碼:

try{ 
           HttpPost post = new HttpPost("http://qa.mobile.equinix.com/eqixmobile/siteservice/order/getsitevisitsByCustOrgId"); 
           StringEntity se = new StringEntity("{\"userKey\":\"68782\",\"custOrgId\":\"37\",\"credentials\":{\"password\":\"welcome1\",\"username\":\"mobileuser1\"},\"ibxCode\":\"SV1\",\"orderStatusList\":[\"SAVED\",\"SUBMITTED\"],\"pagination\":{\"pageNo\":1,\"pageSize\":6}}"); 
           obj = new Service_Call(post, se, "mobileuser1", "welcome1",false);         
           String json_string = obj.call_Service(); 
           new Parse_Json(json_string).parse_ShowOrders(); 
          }catch(Exception e) 
          { 
           e.printStackTrace(); 
          } 

呼叫處理方法:

package com.equinix.android.servicecall; 

import java.io.BufferedReader; 
import java.io.InputStreamReader; 

import org.apache.http.HttpResponse; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.entity.StringEntity; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.message.BasicHeader; 
import org.apache.http.params.HttpConnectionParams; 
import org.apache.http.protocol.HTTP; 
import org.json.JSONObject; 

import com.equinix.android.common.MenuScreen; 
import com.equinix.android.parsing.Parse_Json; 

import com.equinix.android.parsing.Parse_Json; 
import com.equinix.android.sitevisit.Site_Visit_Details; 

public class Service_Call { 

    HttpPost post; 
    StringEntity eq_Credentials; 
    String usr_Name,pass; 
    boolean flag; 
    public static int status_code=0; 
    public Service_Call(HttpPost post,StringEntity eq_Credentials, String usr_Name, String pass,boolean flag) 
    { 
     this.post = post; 
     this.eq_Credentials = eq_Credentials; 
     this.usr_Name = usr_Name; 
     this.pass = pass; 
     this.flag = flag; 
    } 

    public String call_Service() 
    { 
      HttpClient client = new DefaultHttpClient(); 
      HttpConnectionParams.setConnectionTimeout(client.getParams(), 20000); //Timeout Limit 
      HttpResponse response; 

      try{ 
      // HttpPost post = new HttpPost("http://122.180.114.68/eqixmobile/siteservice/um/ibx"); 
      if(flag) 
      { 

       eq_Credentials.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); 
       post.setEntity(eq_Credentials); 

       response = client.execute(post); 
       System.out.println("The request body:"+post); 
      } 
      else 
      { 
       post.setHeader("Content-type", "application/json"); 
       post.setHeader("accept", "application/json"); 
       eq_Credentials.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); 

       post.setEntity(eq_Credentials); 

       response = client.execute(post); 
       System.out.println("The request body:"+post.toString()); 
       status_code = response.getStatusLine().getStatusCode(); 
       System.out.println("The Response Code:"+response.getStatusLine().getStatusCode()); 
      } 



        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); 
        StringBuilder builder = new StringBuilder(); 
        String str=""; 

        String line = null; 
        while ((line = reader.readLine()) != null) { 
         str +=line; 

        } 


       System.out.println(str); 


       return str; 
      } 
      catch(Exception e){ 
       e.printStackTrace(); 

      } 
     return null; 
    } 
} 
+0

提供了一些代碼片段 –

+0

如果您需要獲得幫助,請顯示您正在使用的代碼。 –

+0

雅我提供了它,請參閱編輯的代碼 –

回答

0

請從您的代碼中刪除以下行。

* eq_Credentials.setContentEncoding(新BasicHeader(HTTP.CONTENT_TYPE, 「應用/ JSON」)); *

希望這有助於你。