Linux 常用命令 之 http请求命令 curl

来源:互联网 发布:linux u盘启动盘工具 编辑:程序博客网 时间:2024/05/16 01:57

    curl 命令,可以模拟http 请求,这个命令是很方面的。这样的话,结合linux 自带的定时机制 crontab , 我们就可以很轻松地写出定时调用网络请求的接口。

    curl 命令参数太多, 笔者用到的是模拟 http post 请求,参数为json 字符串, 希望笔者能起到抛砖引玉的作用。


1. 命令格式:

#!/bin/bashcurl -H "Content-type: application/json" -X \     POST -d '{"requestObject":[ 50, 30 ]}' http://127.0.0.1:7080/ok-controller/hello/sayHello.json

2. springmvc 代码:

    spring mvc 修饰的接口,请求参数需要用 @RequestBody 来修饰, 此注解修饰的参数,需使用json 字符串传递,是以字节流传递的,并非在request.getParameter之中,而字节流只能读取一次,不能反复读取。

@RequestMapping("/sayHello.json")@ResponseBodypublic void sayHello(@RequestBody BaseRequest<List<Long>> request){        }


1 0
原创粉丝点击