如何使用restclient来发送post请求参数
来源:互联网 发布:北洋标签打印机软件 编辑:程序博客网 时间:2024/06/08 19:03
我喜欢使用 restclient 来测试我的 REST 风格的应用程序。一般我就是用GET方法,今天用到了POST方法。POST传递参数应该放在body里面,对长度没有限制。不像GET对URL的限制是1024字节。
运行 restclient ,点选Method选项卡的“POST”方法。然后选择Body选项卡,下下拉列表中选择”String body“的选项,配置上 application/x-www-form-urlencoded;charset=UTF-8 。再出现的body里面写入字符串,也就是你的请求条件,如:query=xpsF
这样就可以传递post的参数了。
java代码如下:springmvc写的
@RequestMapping(value = "/test", method = { RequestMethod.GET, RequestMethod.POST }) public void test(HttpServletResponse response, @RequestBody String message) { 这里的:@RequestBody String message LOGGER.debug(String.format("receive message %s", message)); Map<String, String> map = Maps.newHashMap(); try { map.put("result", message); Tools.printToJson(JSON.toJSONString(map), response); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }如果传递的是一个对象给springmvc,如(代码不全):
public class EntitySubscribe { private Long entityId; private String entityCode; private String entityName; private String teamCode; private SubscribeUsesEnum subscribeUsesEnum; private Date gmtCreate; private Date gmtModify; private Long flowId; private OnOffEnum state; private String reason; private List<Integer> uses; }
@ResponseBody @RequestMapping(value = "/subscribeEntity", method = { RequestMethod.POST }) public AjaxResult subscribeEntity(@RequestBody EntitySubscribe entitySubscribe, @CookieValue( value = Const.COOKIE_USER_KEY, required = false) String userId) { LOGGER.debug(this.getClass().getName() + "#subscribeEntity"); long entityId = entitySubscribe.getEntityId(); String teamCode = entitySubscribe.getTeamCode(); String subscribeUses = Joiner.on(",").skipNulls().join(entitySubscribe.getUses()); String reason = entitySubscribe.getReason(); Preconditions.checkArgument(StringUtils.isNotBlank(teamCode)); Preconditions.checkArgument(StringUtils.isNotBlank(subscribeUses)); Preconditions.checkArgument(StringUtils.isNotBlank(reason)); Preconditions.checkArgument(StringUtils.isNotBlank(userId)); return entitySubscribeService.subscribeEntity(entityId, teamCode, subscribeUses, reason, userId);
使用restclient的请求为 :POST
String body 为: application/json; charset=UTF-8
body内容为:{"entityId":343,"reason":"for test测试","teamCode":"cdc","uses":[1,2,3]}
这样后台就能收到对象了。
0 0
- 如何使用restclient来发送post请求参数
- FireFox插件RESTClient 如何使用POST,请求json数据参数。
- 如何使用火狐下的两款接口测试工具RESTClient和HttpRequester发送post请求
- 火狐浏览器使用RESTClient发送post请求方法
- 火狐浏览器使用RESTClient发送post请求方法
- restclient使用get,post方式发送http请求
- 火狐插件restclient发送post请求
- Firefox restClient如何发送post请求解决方法---谷营乡中西软件科技园--zdd
- 发送POST请求的工具RESTClient的安装
- 在火狐浏览器使用RESTClient模拟post请求
- 使用FireFox插件RESTClient、HttpRequester模拟http(get post)请求
- restClient模拟post添加参数
- 【Android网络请求】如何使用Volley发送POST请求
- Android使用volley发送带参数的post请求
- 使用HttpURlConnection 发送POST请求上传文件(带参数)
- 在火狐浏览器上安装RESTClient插件可以模拟发送get、post请求
- 火狐两款接口测试工具RESTClient和HttpRequester发送post请求
- 如何使用SOCKET 发送HTTP1.1 GET POST请求包
- tomcat jndi
- Android 开机流程分析
- 返回头部和返回底部
- ios 关于tableview的复用问题,避免假复用
- ios快速界面跳转利器-传送门方案VCPicker
- 如何使用restclient来发送post请求参数
- maven 把 下载的jar包添加到本地仓库 的方法
- frameworks.sh: No such file or directory
- oracle查询包含大小写的数据
- 用H5 Canvas 绘画箭头
- hah
- tomcat异常关闭后再启动报错:IOException while loading persisted sessions: java.io.EOFException
- LeetCode11. Container With Most Water(思维题:选择左右边使得容器所盛水最多)
- 使用Powermock实现单元测试,提高单元测试覆盖率