嗯,对 android 很陌生,并试图通过 android 向 URL 发帖。我的网址看起来像这样。
http://192.168.101.111:7000/MyService.svc/home/updatejob/4600/XCV13030001/TTTT0000/CCCC0000/SSSS0000
我可以通过 Advance rest 客户端向这个 url 发布一个帖子,这工作正常。这是我的android代码实现
public boolean updateInfo() {
boolean result = false;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sbDriverID", sbDriverID.toString()));
params.add(new BasicNameValuePair("sbJobNumber", sbJobNumber.toString()));
params.add(new BasicNameValuePair("sbTrailerNumber", sbTrailerNumber.toString()));
params.add(new BasicNameValuePair("sbContainerNumber", sbContainerNumber.toString()));
params.add(new BasicNameValuePair("sbSealNumber", sbSealNumber.toString()));
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
if (httpResponse != null) {
if (httpResponse.getStatusLine().getStatusCode() == 204)
result = true;
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
这给我一个 404。我很努力,找不到原因。