2011-09-27 147 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”)); *

希望这有助于你。