简体   繁体   中英

Web Service request is not working in android browser and code; but it is working in pc browser

My PC is connected to client's network via tunneling and I am calling a webservice which is in client's network. This works fine in PC Browsers, where as when I try to access it via android application I am getting ClientProtocolException . I tried to hit the web service ip via android browser I was able to see the IIS server response in browser but couldn't access the webservice. Not an https url, just normal http url. It's not working in any version of android emulator.

Code :

HttpClient httpclient = new DefaultHttpClient();

HttpGet httpget = new HttpGet(url); 

HttpResponse response;

try {
    response = httpclient.execute(httpget);

    Log.i("Debug",response.getStatusLine().toString());

    HttpEntity entity = response.getEntity();

    if (entity != null) {

        ....
    }


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

它可能是您的Android设备上可能阻止访问Web服务的防火墙应用程序(我的知识没有内置)。

Actually there is no response headers in the webservice. That is why I got the exception. Now I opened a socket to get the response, but still a request without proper response header is not good.

Have you tried setting up a Web proxy?

httpclient.getHostConfiguration().setProxy("ip-address","port")

or

System.setProperty("http.proxyHost", "ip-address");
System.setPropery("http.proxyPort", "port");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM