简体   繁体   English

Web服务请求在android浏览器和代码中不起作用; 但它在PC浏览器中工作

[英]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. 我的PC通过隧道连接到客户端的网络,我正在调用客户端网络中的Web服务。 This works fine in PC Browsers, where as when I try to access it via android application I am getting ClientProtocolException . 这在PC浏览器中运行良好,当我尝试通过Android应用程序访问它时,我得到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. 我尝试通过Android浏览器点击Web服务ip我能够在浏览器中看到IIS服务器响应但无法访问web服务。 Not an https url, just normal http url. 不是https网址,只是普通的网址。 It's not working in any version of android emulator. 它不适用于任何版本的Android模拟器。

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. 实际上,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? 您是否尝试过设置Web代理?

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

or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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