只是一些入门信息。我正在编写一个 Andorid 应用程序,它使用 MVC 平台与用 C#.Net 编写的服务器进行通信。每个请求都是一个帖子,ActionFilter 属性可以确保这一点。然而,由于这个问题,.Net 将 HttpMethod 解析为“ST”。
以下是我在全局范围内使用的从我的应用程序发出 Web 请求的代码:
private String MakeRequest(String action, String params){
try {
HttpPost request = new HttpPost(mProtocol + mSubDomain + mHost + action);
String args;
if (params != null) {
args = params;
} else {
args = "[]";
}
StringEntity requestEntity;
requestEntity = new StringEntity(args);
requestEntity.setContentType("application/json;charset=UTF-8");
requestEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
request.setEntity(requestEntity);
HttpResponse response = mHttpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
String jString = EntityUtils.toString(responseEntity);
return jString;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我只在一种特定方法上遇到这个问题,所有其他方法都工作得很好。
以下链接指向包含流量的 pcap 文件,因此该文件清晰可见。 (我已将其过滤为仅适用的行) http://dl.dropbox.com/u/315661/defect.pcap
最佳答案
您是否尝试过在 POST 中禁用 100-Continue?您通常不需要它,因为它只会增加与服务器的通信的更多开销 - 如果服务(或您的设备和服务之间的任何套件)可能会导致问题,例如代理等)您发布的内容不完全符合。
HttpProtocolParams.setUseExpectContinue(params, false)
关于java - 为什么我的 HttpPost 请求被分成两个请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8146788/