我用这个来测试dmy,身体是JSON格式的。所以请将您的Student对象转换为JSON数据。
public String post(String url, HashMap<String, String>params, String body) throws Exception {
HttpPost postRequest = new HttpPost(url);
for(String key : params.keySet()){
postRequest.addHeader(key, params.get(key));
}
StringEntity input = new StringEntity(body);
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = (new DefaultHttpClient()).execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String output;
StringBuffer totalOutput = new StringBuffer();
while ((output = br.readLine()) != null) {
totalOutput.append(output);
}
return totalOutput.toString();
}