下面这个curl命令是post一个json到web服务端:
curl "http://localhost:8080/api/authenticate" -X POST -H "Content-Type: application/json" -d '{"username": "admin", "password": "admin"}'
这个使用linux下的curl运行是没有问题的,但使用Windows自带的curl运行时,经过抓包分析发现,它会改变发送的内容,比如这里想要发送一个json,它却自作聪明的去掉双引号,导致服务端不能正常解析。需要修改为下面的形式:
curl "http://localhost:8080/api/authenticate" -X POST -H "Content-Type: application/json" -d "{\"username\": \"admin\", \"password\": \"admin\"}"
Windows把curl集成进系统文件“C:\Windows\System32\curl.exe”,可见curl的使用普遍性。curl还是http调试必备的一个命令行工具,个人认为命令行的工具比有界面的工具如postman更好用。