【发布时间】: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