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 ...
随机推荐
- SnowNLP:•中文分词•词性标准•提取文本摘要,•提取文本关键词,•转换成拼音•繁体转简体的 处理中文文本的Python3 类库
SnowNLP是一个python写的类库,可以方便的处理中文文本内容,是受到了TextBlob的启发而写的,由于现在大部分的自然语言处理库基本都是针对英文的,于是写了一个方便处理中文的类库,并且和Te ...
- Oracle查看数据库表的创建时间
select OBJECT_NAME, CREATED from DBA_OBJECTS obj, USER_TABLES tab where obj.OBJECT_NAME = tab.TABLE_ ...
- Don’t Put View Code Into Your View Controller别把View创建的代码放在VC中(swift)
Don't Put Into Your View Controller别把View创建的代码放在VC中html, body {overflow-x: initial !important;}.Code ...
- C语言 · 递归倒置字符数组
算法提高 递归倒置字符数组 时间限制:1.0s 内存限制:512.0MB 问题描述 完成一个递归程序,倒置字符数组.并打印实现过程 递归逻辑为: 当字符长度等于1时,直接返回 否则, ...
- android——字符串string(转)
原文地址:http://www.open-open.com/lib/view/open1387942832078.html String : 字符串类型 一.构造函数 String(byte[ ...
- JMeter (3) —— JMeter录制脚本并压力测试用户登陆场景以CAS SSO为例(101 Tutorial)
JMeter (3) -- JMeter录制脚本并压力测试用户登陆场景以CAS SSO为例(101 Tutorial) 主要内容 JMeter录制脚本并进行压力测试用户登陆场景,并以CAS SSO单点 ...
- Java编程的逻辑 (46) - 剖析PriorityQueue
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...
- 【linux】——一个小程序
利用工作之余为小伙伴写了份作业,关于进程间通信的.题目如下: 父进程从键盘上接受1000个数据,对其求和sum1,子进程对这1000个数平方和sum2,结果传给父进程,父进程将sum1+sum2后,打 ...
- vbs中的"WScript.Network"[属性与方法]
属性ComputerName 计算机名UserDomain 所属局域网域的域名UserName ...
- jQuery(七):节点操作
jQuery中节点操作主要分为以下几种: 查找节点. 创建节点. 插入节点. 替换节点. 复制节点. 删除节点. 一.查找节点 示例: <!DOCTYPE html> <html l ...