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 ...
随机推荐
- VMWare: eth0: error fetching interface information : device not found
VMWare: eth0: error fetching interface information : device not found 今天在VMware上新搭建的Redhat Linux 64 ...
- [转]SSH和SSM对比总结
原文地址:https://blog.csdn.net/peak_and_valley/article/details/52925032 当下流行的两种企业开发MVC开源框架,是我们Java程序猿必备知 ...
- AlphaGo论文的译文,用深度神经网络和树搜索征服围棋:Mastering the game of Go with deep neural networks and tree search
转载请声明 http://blog.csdn.net/u013390476/article/details/50925347 前言: 围棋的英文是 the game of Go,标题翻译为:<用 ...
- 轻松学习JavaScript二十七:DOM编程学习之事件模型
在介绍事件模型之前,我们先来看什么是事件和什么是event对象. 一事件介绍 JavaScript事件是由訪问Web页面的用户引起的一系列操作,使我们有能力创建动态页面.事件是能够被 JavaScri ...
- APUE信号-程序汇总
APUE信号-程序汇总 近期重看APUE,发现对于非常多程序的要领还是没有全然理解.所以梳理下便于查看,并且有非常多值得思考的问题. 程序清单10- 1 捕获 SIGUSR1 和 SIGU ...
- SQL中的DML、DDL以及DCL是什么?
DML(data manipulation language)是数据操纵语言:它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的 ...
- 【WPF】TextBlock文本文字分段显示不同颜色
需求:一行文字中,不同字符显示不同颜色.如注册页面,为表示必填项,在文本最后加一个红色的型号* 目标效果: 方法一: 用< StackPanel >嵌套两个< TextBlock & ...
- WPF通过EventTrigger改变其他控件的值
场景:点击TextBox后弹出Poppup 原理:使用EventTrigger后触发StoryBoard,通过StoryBoard改变其他控件的值. 参考代码: <Grid> <Gr ...
- MSSQL跨服务器查询
1.因为此功能服务器安全配置的一部分而被关闭,所以我们先开启 reconfigure reconfigure 2.如果需要关闭,执行 reconfigure reconfigure 3.查询语句 SE ...
- awk的替代先sort 再uniq -c 再sort ,uniq只能队相邻的起作用sort先让之间相邻再sort,最后sort是数量排序
[root@localhost ~]# cat aa.txt |sort|uniq -c|sort -nk1 1 22\ 1 44 1 55\ 1 bb 1 dd 1 ff 1 gg 1 kk 1 o ...