码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-05-28 00:54:28      阅读:1014      评论:0      收藏:0      [点我收藏+]

标签:bsp   create   int   eth   exec   aot   creat   control   cli   

  方案: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错误

标签:bsp   create   int   eth   exec   aot   creat   control   cli   

原文地址:http://www.cnblogs.com/xiaohouzai/p/6914821.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!