使用curl -X 发送Http请求


一、curl是什么?

curl是一个命令行工具,通过指定的URL来上传或下载数据,并将数据展示出来。curl中的c表示client,而URL,就是URL。 curl支持的通信协议有FTP、FTPS、HTTP、HTTPS、TFTP、SFTP、Gopher、SCP、Telnet、DICT、FILE、LDAP、LDAPS、IMAP、POP3、SMTP和RTSP。

二、curl -X http使用案例

1.get请求

代码如下(示例):
curl -X GET "http://localhost:8082/system/user/query/forward/orgs?userId=683857731272960&userName=xiaoming" -H "accept: */*"
在这里插入图片描述

格式:

 curl -X GET "请求地址+参数" -H "accept: */*"   //多个参数之间用&分隔

2.post请求

普通的Post请求:
curl -X POST "http://localhost:8082/system/user/query/forward/orgs?userId=683857731272960&userName=xiaoming" -H "accept: */*"
在这里插入图片描述

格式:

 curl -X POST  "请求地址+参数" -H "accept: */*" 
 //多个参数之间用&分隔,记得双引号不能少,测试过去的,少了会报错
 //-H 表示头部,及header

Post JSON请求:
curl -X POST "http://localhost:8082/system/user/updatedDataForwardingUser" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"userId\": \"1234567890\", \"userName\": \"test\", \"userType\": \"4\"}"
在这里插入图片描述

格式:

 curl -X POST  "请求地址+参数" -H "Content-Type:application/json" -d "请求体(body)"
 //多个参数之间用&分隔,记得双引号不能少,测试过去的,少了会报错
 //-H 表示头部,及header
 //-d 请求的body,及data

  • 7
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值