我正在使用Apache HTTP Client,我需要向我的servlet发送POST请求.发送请求时,我的servlet没有收到任何参数(在HttpServletRequest)中.
这是客户端程序代码:
// Engage the HTTP client
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
try {
HttpPost httpPost = new HttpPost("http://localhost:8080/test-json-web/JSONReceiverServlet");
// Setup the request parameters
HttpParams params = new BasicHttpParams();
params.setParameter("taskdef", task1JsonString);
httpPost.setParams(params);
// Make the request
response = httpclient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if(responseEntity != null) {
System.out.println("Response content length: " + responseEntity.getContentLength());
}
String jsonResultString = EntityUtils.toString(responseEntity);
EntityUtils.consume(responseEntity);
System.out.println("----------------------------------------");
System.out.println("result:");
System.out.println();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) …Run Code Online (Sandbox Code Playgroud)