Curl
发送POST请求
JSON得转义
curl -X POST -H "Content-Type:application/json" -H "Accept:*/*" -d "{ \"hello\":\"world\"}" http://localhost:8080/user
要想将JSON变成curl命令想要的形式,得将"
=> \"
,下面给一个转化的例子。
public static void main(String[] args) {
Gson gson=new Gson();
HashMap<String,String> map=new HashMap<>();
map.put("hello","world");
String mapStr=gson.toJson(map);
System.out.println(mapStr);
mapStr=mapStr.replaceAll("\"","\\\\\"");
System.out.println(mapStr);
}
HTTPie
yum -y install httpie
发送POST请求
[root@desktop-c0aek27 ~]# http POST http://192.168.1.7:8080/user2 < req.json
HTTP/1.1 200
Connection: keep-alive
Content-Type: application/json
Date: Thu, 01 Oct 2020 03:32:45 GMT
Keep-Alive: timeout=60
Transfer-Encoding: chunked
{
"address": {
"name": "oneslide"
},
"hello": "world"
}