curl 与 httpie 命令

curl 命令参数

-o  #output保存到文件中	curl -o [文件名] www.sina.com

-i  #显示 response的头信息	curl -i www.sina.com

-v  #显示详细信息

-X  #默认是 GET ,可以指定 POST PUT 等

-h / --header  #添加头信息

-d/ --data
#发送数据
#  发送表单参数 -d '{"name":"lisi","age":14}'
#  请求头参数(类似 your_url?a=1&b=2) -d "a=1&b=2" 

-u/--user
#  http认证	curl --user name:password example.com

示例:

发送 json表单请求

curl -H "Content-Type: application/json" -d '{"name":"admin","password":"admin"}' http://request_url

发送 post请求

curl -X POST http://your_url

 

httpie 命令参数

安装 请移步github

语法格式: 

http [flags] [METHOD] URL [ITEM [ITEM]]

请求项

Item TypeDescription
HTTP HeadersName:ValueArbitrary HTTP header, e.g. X-API-Token:123.
URL parametersname==valueAppends the given name/value pair as a query string parameter to the URL. The ==separator is used.
Data Fieldsfield=value,field=@file.txtRequest data fields to be serialized as a JSON object (default), or to be form-encoded (--form, -f).
Raw JSON fieldsfield:=json,field:=@file.jsonUseful when sending JSON and one or more fields need to be a BooleanNumber, nested Object, or an Array, e.g., meals:='["ham","spam"]' or pies:=[1,2,3] (note the quotes).
Form File Fieldsfield@/dir/fileOnly available with --form, -f. For example screenshot@~/Pictures/img.png. The presence of a file field results in a multipart/form-data request.

示例

json data

http PUT example.org name=John

form data

http -f POST example.org hello=World

query params

http www.google.com search=='HTTPie logo' tbm==isch

Digest auth

http -A digest -a username:password example.org

 

转载于:https://my.oschina.net/lemos/blog/919791

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值