curl

作者: svatyvabin | 来源:发表于2017-09-13 15:45 被阅读5次

常用请求

-X POST 表示发送 POST 请求,可将 POST 改成 GET, DELETE, PUT 等其他请求方式
--header 表示头,可以简写成 -H
--data 表示请求的数据部分,可简写成 -d,用于 POST, PUT 等
-i 表示输出包含 header 的信息

curl -X POST -i --header 'Content-Type: application/json;charset=UTF-8' --data '{"username":"user"}' http://localhost/v1/users

gzip 压缩

-H "Accept-Encoding: gzip" 接受gzip压缩
-I 显示头信息,不输出内容
--write-out "%{size_download}\n" 输出返回的大小
--output a.txt 将返回结果重定向到 a.txt 文件

上传文件

将当前目录的 file.txt 文件和 img.png 图片上传到服务器:
-F 不需要再声明 Content-Type

curl -F 'file=@file.txt' -F 'img=@img.png' http://localhost/upload

更详细的介绍可以查看官方 Manual

相关文章

网友评论

      本文标题:curl

      本文链接:https://www.haomeiwen.com/subject/gmkwattx.html