访问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();
}

 

 

 

posted on 2017-05-28 00:29  尴尬而不失礼貌的微笑  阅读(1488)  评论(0编辑  收藏  举报