开发者

Web Service is not Responding

开发者 https://www.devze.com 2023-04-08 02:51 出处:网络
I have a problem that I am calling a webservice which is running on Google Chrome RESTClient AddON Software and gives 200 response but when I called the same in my Android App It is not responding.

I have a problem that I am calling a webservice which is running on Google Chrome RESTClient AddON Software and gives 200 response but when I called the same in my Android App It is not responding.

I don't know what is the problem for Android. Please suggest me for the right result.

Thanks

Error Stack

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)

Code:

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

Call Service Method:

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.equi开发者_运维技巧nix.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;
    }
}


Please Remove the following line from your code.

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

Hope this help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消