首页 > 代码库 > 访问taotao-portal 中controller中返回taotaoresult 测试httppost方法 出现406错误

访问taotao-portal 中controller中返回taotaoresult 测试httppost方法 出现406错误

  方案:1.检查jackson包是否存在

 

技术分享

 

@controller

@RequestMapping(value = "http://www.mamicode.com/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错误