訪問taotao-portal 中controller中返回taotaoresult 測試httppost方法 出現406錯誤
方案:1.檢查jackson包是否存在
@controller
@RequestMapping(value = "/httpclient/post",method=RequestMethod.POST)
@ResponseBody
public TaotaoResult testPost(String username,String password){
system.out.println( "username" + username + "/t password" + password);
return TaotaoResult.ok();
}
2.後綴名是.html結尾的,是不能返回json數據的。需要修改後綴名為其他的。如.do。或者.action
@Test
public void doPost() throws Exception, IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
// 創建一個post對象
HttpPost post = new HttpPost("http://localhost:8082/httpclient/post.do");
// 執行post請求
CloseableHttpResponse respose = httpClient.execute(post);
String string = EntityUtils.toString(respose.getEntity());
System.out.println(string);
respose.close();
httpClient.close();
}
訪問taotao-portal 中controller中返回taotaoresult 測試httppost方法 出現406錯誤