【问题标题】:Android web service call throws org.apache.http.NoHttpResponseExceptionAndroid Web 服务调用抛出 org.apache.http.NoHttpResponseException
【发布时间】:2015-01-07 11:38:06
【问题描述】:

我做了什么:

我已尝试使用以下代码从我的 android 应用程序中通过 "POST" 方法调用 Web 服务。

       HttpClient httpclient = new DefaultHttpClient();
       HttpPost httppost = new HttpPost("http://myserver.com:5060/convert/service");
       try {
           File file = new File(inputPath);
           httppost.setHeader("Content-Type", "application/msword");
           httppost.setHeader("Accept", "application/pdf");
           httppost.setEntity(new ByteArrayEntity(readFile(file)));

           // Execute HTTP Post Request
           HttpResponse response = httpclient.execute(httppost);

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

当我执行此 api 调用时,我收到以下异常。

"org.apache.http.NoHttpResponseException: 目标服务器失败 回应”

但是当我使用 same code独立 java 项目 调用 same web service 时,我得到了正确的回应

没有出现上述任何错误。

我想要什么:

根据我的java web 服务调用,我知道服务和源代码都没有问题。那么可能是什么问题?我怎样才能摆脱这个问题?

【问题讨论】:

  • HttpPost httppost = new HttpPost("我的服务网址");你确定my service url 需要用引号引起来吗?
  • @Skynet:我已经更新了我的问题。

标签: java android web-services exception http-post


【解决方案1】:

我已经解决了这个问题。

问题是由于端口号 5060。我确实通过在 Eclipse 中使用 TCP/IP 监视器 工具发现了这一点。

默认情况下 5060 端口 没有从 android 调用(我不知道原因)。因为请求没有到达服务器。

所以我在我的服务器中将端口号更改为8090并重新启动了服务器。

然后我从 android 调用了该服务。现在效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2012-01-04
    • 2012-03-06
    • 1970-01-01
    • 2015-08-19
    • 2014-11-02
    相关资源
    最近更新 更多