我正在開發一個Android和Java的服務器應用程序。 服務器應用程序在Jetty上運行。 Android應用程序在同一臺計算機上模擬。POST請求變成GET
Android應用程序向服務器發送POST請求,但服務器的處理程序將其解釋爲GET。
當我使用發送HTTP工具來模擬POST請求,它完美的作品(我的意思是方法的類型是POST)。
這是Android應用程序的代碼片段:
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(),
10000); // Timeout Limit
HttpResponse response;
// Create message
JSONObject json = new JSONObject();
json.put("request_type", "info");
json.put("user_name", mEmail);
// Send message and get response
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
HttpPost post = new HttpPost("http://10.0.2.2:8080/app");
post.setEntity(se);
post.setHeader("Accept", "application/json");
post.setHeader("Content-Type", "application/json; charset=UTF-8");
response = client.execute(post);
這是處理程序的代碼:
public void handle(String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response) {
System.out.println(request.getMethod());
}
我不知道這可能是一個問題,我認爲如果我使用HttpPost,方法類型應該是POST。
什麼是'postGetSalt'? –
這是「發佈」變量的原始名稱。我改變了它,但不幸的是沒有到處。我糾正了。 – szedjani