curl tutorial with examples of usage
原文:http://www.yilmazhuseyin.com/blog/dev/curl-tutorial-examples-usage/
阮一峰的这个教程也不错:http://www.ruanyifeng.com/blog/2011/09/curl.html
Curl is a linux utility that is used to make HTTP requests to a given url. It outputs HTTP response to standard output and is actually very easy to use. Here are some examples to show its usage:
Make a GET request without any data:
curl http://yilmazhuseyin.com/blog/dev/
curl --request GET 'http://yilmazhuseyin.com/blog/dev/'
Both usages are actually the same. However, I try to use second one all the time. With --request (or -X) parameter, we choose our http method to use for our requests. Its values can be GET, POST, DELETE, PUT etc.. If we don't specify this parameter, GET method will be used by default. That is why first version works same as the second one.
Make requests with different HTTP method type without data:
curl --request POST 'http://www.somedomain.com/'
curl --request DELETE 'http://www.somedomain.com/'
curl --request PUT 'http://www.somedomain.com/'
Make requests with data:
Since we learn how to make POST, GET, PUT, DELETE requests, we can now make same requests with data. In order to send data with those requests, we should use --data parameter. Here are some examples:
::::/bin/bash
# send login data with POST request
curl --request POST 'http://www.somedomain.com/login/' \
--data 'username=myusername&password=mypassword'# send search data to with get request
curl --request GET 'http://www.youtube.com/results?search_query=my_keyword'# send PUT request with data
curl --request PUT 'http://www.somedomain.com/rest-api/user/12345/'\
--data 'email=myemail@gmail.com'# same thing but this one get data from a file named data.txt
curl --request PUT 'http://www.somedomain.com/rest-api/user/12345/'\
--data @data.txt
Make requests with extra headers
Sometimes you need to add HTTP headers to your requests. This is done by --header parameter.
curl --request GET 'http://www.somedomain.com/user/info/' \
--header 'sessionid:1234567890987654321'
Notice that we are using semicolon(":") to separate header name from its value.
Get response with HTTP headers
If you need to get HTTP headers with your response, --include parameter can be used
curl --request GET 'http://somedomain.com/'--include
Those examples cover most of the stuff curl is needed for. If you need more functionality, you can use following two commands as a reference
# gives brief description of parameters
curl --help
# curl manual page
man curl
TODO: add cookie parameters
curl tutorial with examples of usage的更多相关文章
- A Complete Guide to Usage of ‘usermod’ command– 15 Practical Examples with Screenshots
https://www.tecmint.com/usermod-command-examples/ -------------------------------------------------- ...
- A GDB Tutorial with Examples--转
http://www.cprogramming.com/gdb.html A GDB Tutorial with Examples By Manasij Mukherjee A good debugg ...
- 7 Best jQuery & JavaScript PDF Viewer plugin with examples
In this Post we are providing best jQuery PDF viewer plugin & tutorial with examples.Due to popu ...
- Why GraphQL is Taking Over APIs
A few years ago, I managed a team at DocuSign that was tasked with re-writing the main DocuSign web ...
- kubernetes网络排错思想
Overview 本文将引入一个思路:"在Kubernetes集群发生网络异常时如何排查".文章将引入Kubernetes 集群中网络排查的思路,包含网络异常模型,常用工具,并且提 ...
- [转]bitcoin API reference (JSON-RPC)
本文转自:https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#Node.js API reference (JSON-RPC) Co ...
- 【大数据系列】apache hive 官方文档翻译
GettingStarted 开始 Created by Confluence Administrator, last modified by Lefty Leverenz on Jun 15, 20 ...
- Django 2.0.1 官方文档翻译: 文档目录 (Page 1)
Django documentation contents 翻译完成后会做标记. 文档按照官方提供的内容一页一页的进行翻译,有些内容涉及到其他节的内容,会慢慢补上.所有的翻译内容按自己的理解来写,尽量 ...
- jar命令使用介绍
http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html Skip to Content Oracle Technol ...
随机推荐
- C#学习笔记(27)——委托排序(1)
说明(2017-11-20 17:21:35): 1. 感觉难点都在冒泡排序上..貌似之前跳过去了没学啊!冒泡排序的精髓就在于,两两比较,最大的排到最后一位,再把前面的重新两两比较,把最大的排到倒数第 ...
- [转]oracle在删除表\表空间\用户时,如何释放磁盘空间
一.drop表 执行drop table xx 语句 drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 通过查询回收站 ...
- Laravel Eloquent使用小记
原文地址:http://blog.onlywan.cc/14843810761202.html Laravel Eloquent使用小记 今天由于开发数据库业务中间层须要.開始研究Laravel El ...
- regsvr32.exe是什么东西
Regsvr32命令修复系统故障实例使用过activex的人都知道,activex不注册是不能够被系统识别和使用的,一般安装程序都会自动地把它所使用的activex控件注册,但如果你拿到的一个控件需要 ...
- git学习相关的博客地址
Git分支管理策略: http://www.ruanyifeng.com/blog/2012/07/git.html Git 使用规范流程: http://www.ruanyifeng.com/blo ...
- Android——FilenameFilter总结(转)
一.FilenameFilter介绍 java.io.FilenameFilter是文件名过滤器,用来过滤不符合规格的文件名,并返回合格的文件: 一般地: (1)String[] fs = f.l ...
- 【进阶修炼】——改善C#程序质量(4)
46, 显示释放资源,需要实现IDisposable接口. 最好按照微软建议的Dispose模式实现.实现了IDisposable接口后,在Using代码块中,垃圾会得到自动清理. 47, 即使提供了 ...
- iwebshop 模板手册
1.面包屑 <div class="position"><span>您当前的位置:</span><a href="{url:}& ...
- Extjs4.2 Tree使用技巧小结demo
本案例使用了Ext.Tree.Panel的如下知识点: 1.刷新.重新加载Tree,定位到上次的节点位置 2.Tree的右键操作 3.Extjs4.x Tree获取当前选中的节点 4.新增.修改.删除 ...
- fiddler手机端抓包
1. 买个360随身wifi,插在台式机上生成热点,手机连上自己的wifi 如果电脑与手机本就在一个局域网,省略这一步 2. 在fiddler中如下设置: 3. 查看电脑无线连接属性 4. 在手机上设 ...