Linux系统中使用CURL模拟请求HTTP服务

1.安装

cURL is a command-line utility for transferring data from or to a remote server using one of the supported protocols.

It is installed by default on macOS and most Linux distributions.

wget http://curl.haxx.se/download/curl-7.19.6.tar.gz 

tar -zxvf curl-7.19.6.tar.gz 

cd curl-7.19.6 

./configure --prefix=/usr/local/curl 

make 

make install

 无法访问互联网下载的用户,可以在互联网下载好,导入到内网。

2.使用

2.1用法

curl -X POST [options] [URL]

The -X option specifies which HTTP request method will be used when communicating with the remote server.

2.2 提交multipart/form-data数据

下边是文件上传的例子

# 文件上传
curl -X POST url  -F 'sbbh=A65DADBE166594FA70B622E29C45F935' -F file=@/data/zzzd/reg_record.mp3'

When the -F option is used, curl sends the data using the multipart/form-data Content-Type.

2.3 提交application/x-www-form-urlencoded数据

curl -X POST -d 'name=linuxize' -d 'email=linuxize@example.com' https://example.com/contact.php

If the -d option is used more than once you can merge the data using the & symbol

curl -X POST -d 'name=linuxize&email=linuxize@example.com' https://example.com/contact.php

 2.4 指定特定的Content-Type

To set a specific header or Content-Type use the -H option. The following command sets the POST request type to application/json and sends a JSON object

curl -X POST -H "Content-Type: application/json" -d '{"name": "linuxize", "email": "linuxize@example.com"}'  https://example/contact

3.参考来源

Curl Documentationhttps://curl.se/docs/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值