一、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