curl发送post请求时携带请求体、保存文件等

  1. curl 发送post等请求,使用-X POST指定,如果是put,则-X PUT
    curl -X POST http://xxx.com
    
  2. curl 发pos请求时指定头信息
    curl -X POST -H "Content-Type: multipart/form-data;" http://xxx.com
    
    curl -X POST -H "Content-Type: application/json;charset=UTF-8" http://xxx.com
    
  3. curl 发pos请求时,携带json请求体
    curl -X POST -H 'Content-Type: application/json;charset=UTF-8' -d '{data:"xxx"}' http://xxx.com
    
  4. curl 发pos请求时,使用form-data上传文件,通过-F指定时,-H "Content-Type: multipart/form-data;"可省略
    curl -X POST -F "file=@d:/data/xxx.txt" http://xxx.com
    或
    curl -X POST -H "Content-Type: multipart/form-data;" -F "file=@d:/data/xxx.txt" http://xxx.com
    
  5. curl 发pos请求时,使用form-data上传文件的同时携带其他form-data请求参数
    curl -X POST -F "file=@d:/data/xxx.txt" -F "param1=xxx" "param2=xxx" http://xxx.com
    
  6. curl 发请求时,使用-v可以显示请求底层请求和响应的详细信息
    curl -X POST http://www.baidu.com -v
    
    *   Trying 110.242.68.4:80...
    * Connected to www.baidu.com (110.242.68.4) port 80 (#0)
    > POST / HTTP/1.1
    > Host: www.baidu.com
    > User-Agent: curl/8.0.1
    > Accept: */*
    >
    < HTTP/1.1 302 Found
    < Connection: keep-alive
    < Content-Length: 17931
    < Content-Type: text/html
    < Date: Wed, 13 Sep 2023 02:27:32 GMT
    < Etag: "54d97483-460b"
    < Server: bfe/1.0.8.18
    <
    <html>...</html>
    
  7. curl 下载文件,保留为原始文件名
    curl -O -J "http://xxx"
    
  8. curl 下载文件,自定义文件名
    curl -o xxx.zip "http://xxx"
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

L-960

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值