当前位置: 代码网 > 服务器>服务器>Linux > 关于curl命令行发送post/get请求方式

关于curl命令行发送post/get请求方式

2025年05月22日 Linux 我要评论
curl概述curl 是一个命令行实用程序,允许用户创建网络请求curl 在windows、 linux 和 mac 上皆可使用post请求一个简单的 post 请求:-x:指定与远程服务器通信时将使

curl概述

curl 是一个命令行实用程序,允许用户创建网络请求

curl 在windowslinuxmac 上皆可使用

post请求

一个简单的 post 请求:

  • -x指定与远程服务器通信时将使用哪种 http 请求方法
curl -x post http://example.com

post 请求传递数据:

  • -d:设置请求参数(拼接参数或json)
curl -x post http://example.com -d "firstname=john&lastname=andrew" 
  • -h:设置request里的header
curl -x post http://example.com -d '{"hello": "world"}' -h 'content-type: application/json'
  • -f:模拟http表单数据提交 multipart post使用该-f选项时,curl使用的默认content-type是“multipart/form-data”
curl -x post http://example.com -f 'name=jason' -f 'email=jason@example.com'

get请求

带参数请求,参数用&连接

curl http://127.0.0.1:8080/login?admin&passwd=12345678

apifox工具获取

如下直接复制工具生成的即可,请求头请求体都包含了

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com