原文: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. JAVA-JSP内置对象

    相关资料:<21天学通Java Web开发> request 请求对象 类型javax.servlet.ServletRequest 作用域Requestresponse 响应对象 类型j ...

  2. python 基础总结1

    1.python简介特点:    是简单义学,有功能强大,高性能.面向对象,对动态输入的支持.解释性语言的本质,是大多数平台上理想的脚本语言. 简单,义学                    免费, ...

  3. fast neural style transfer图像风格迁移基于tensorflow实现

    引自:深度学习实践:使用Tensorflow实现快速风格迁移 一.风格迁移简介 风格迁移(Style Transfer)是深度学习众多应用中非常有趣的一种,如图,我们可以使用这种方法把一张图片的风格“ ...

  4. Redis基准

    Redis的基准是实用程序运行n个命令检查Redis 的性能. 语法 redis的基准的基本语法如下所示: redis-benchmark [option] [option value] 例子 下面给 ...

  5. 【驱动】——错误: 初始值设定项里有未知的字段‘ioctl’

    这个错误网上搜索发现3.0.0.15版本内核 file_operation结构体已经删除了ioctl函数,取代的是: long (*unlocked_ioctl) (struct file *, un ...

  6. python 基础干货 02

    list 与 tuple list 类似 数组 tuple 跟 list 一样, 只是一旦定义, 里边的内容不可以改变. 这样, 上边的内容就不可以改变了. "可变的" tuple ...

  7. JavaScript: The Good Parts

    Chapter 1 Good Parts: JavaScript is an important language because it is the language of the web brow ...

  8. PriorityQueue的Java实现

    借助heap数据结构实现. 以小顶heap为例(说明值越小优先级越高,如距离),代码如下: // PriorityQueue.java // Java Spatial Index Library // ...

  9. 《jdk10》删除javah.exe文件,在Android studio编译jni,使用jdk10生成头文件

    今天在用“死丢丢”编译so包的时候,只要一输入"javah -jni..."的命令就会一直提示 'javah'不是内部命令或外部命令,也不是可运行的程序或批处理文件 找了很久才发现 ...

  10. 经典ajax 状态响应图