原文: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的更多相关文章

  1. A Complete Guide to Usage of ‘usermod’ command– 15 Practical Examples with Screenshots

    https://www.tecmint.com/usermod-command-examples/ -------------------------------------------------- ...

  2. A GDB Tutorial with Examples--转

    http://www.cprogramming.com/gdb.html A GDB Tutorial with Examples By Manasij Mukherjee A good debugg ...

  3. 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 ...

  4. 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 ...

  5. kubernetes网络排错思想

    Overview 本文将引入一个思路:"在Kubernetes集群发生网络异常时如何排查".文章将引入Kubernetes 集群中网络排查的思路,包含网络异常模型,常用工具,并且提 ...

  6. [转]bitcoin API reference (JSON-RPC)

    本文转自:https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#Node.js API reference (JSON-RPC)     Co ...

  7. 【大数据系列】apache hive 官方文档翻译

    GettingStarted 开始 Created by Confluence Administrator, last modified by Lefty Leverenz on Jun 15, 20 ...

  8. Django 2.0.1 官方文档翻译: 文档目录 (Page 1)

    Django documentation contents 翻译完成后会做标记. 文档按照官方提供的内容一页一页的进行翻译,有些内容涉及到其他节的内容,会慢慢补上.所有的翻译内容按自己的理解来写,尽量 ...

  9. jar命令使用介绍

    http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html Skip to Content Oracle Technol ...

随机推荐

  1. iOS手机号,身份证,车牌号正则表达式

    1.手机号判断,根据维基百科2016年6月修订的段号判断 是否是手机号 /** 手机号码 13[0-9],14[5|7|9],15[0-3],15[5-9],17[0|1|3|5|6|8],18[0- ...

  2. struts学习笔记

    ------struts in action 读书笔记 1. ActionServlet:Struts 的ActionServlet控制导航流.当ActionServlet从容器接到一个请求,它使用U ...

  3. CLR笔记-枚举类型

    class Program { static void Main(string[] args) { Color color = Color.Red; Console.WriteLine(color.T ...

  4. mac下java环境变量配置

    发现一个坑:最近发现有同事按照本文方式配置jdk环境变量一直不成功,后来发现他是使用了“Oh-My-Zsh”,配置文件的路径不是/etc/profile或~/.bash_profile,它有自己的配置 ...

  5. MySQL Master_Slave主从配置

    一.配置主数据库master 1.在主库Master创建用户. mysql>create user repl; //创建新用户 //repl用户必须具有REPLICATION SLAVE权限,除 ...

  6. CPP_运算符重载及友元

    运算符重载 两种重载方法1)成员函数 a + b => a.operator+(b); 一个参数 2)友元函数 a + b => operator+(a, b); 两个参数. friend ...

  7. oozie无法识别hadoopHA中的ns1

    [hadoop@dwdev-name1 m_goods_sale_detail]$ oozie job -config job.properties -run Error: E1603 : java. ...

  8. 【进阶修炼】——改善C#程序质量(4)

    46, 显示释放资源,需要实现IDisposable接口. 最好按照微软建议的Dispose模式实现.实现了IDisposable接口后,在Using代码块中,垃圾会得到自动清理. 47, 即使提供了 ...

  9. [数据结构]迪杰斯特拉(Dijkstra)算法

    基本思想 通过Dijkstra计算图G中的最短路径时,需要指定起点vs(即从顶点vs开始计算). 此外,引进两个集合S和U.S的作用是记录已求出最短路径的顶点,而U则是记录还未求出最短路径的顶点(以及 ...

  10. sql 字符带下划线匹配问题

    SQL 中 _下划线 作用是 匹配一个任意字符. 如果我们要去掉下划线的作用 单纯只用作一个字符则需要转义成    like '%\_%' escape '\' 字段 1.order_qrsc 2.o ...