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 ...
随机推荐
- [转]java中通过request获取路径中的不同信息
原文地址:http://blog.csdn.net/lv_shijun/article/details/40819859 aa为工程中的项目名 bb为webRoot下的文件夹 1.request.ge ...
- ElasticSearch的安装、使用、踩坑
最近博客写的少了. 本篇介绍在安装ElasticSearch和head插件的过程中遇到的小问题,和一些日常使用的操作(简单搜索语法.分片管理). ElasticSearch 它是一个实时分布式搜索和分 ...
- Selenium学习笔记
Selenium是一个强大的自动化测试工具,它的核心思想是通过JavaScript嵌入的方式直接操纵页面的DOM来模拟手工测试工作. Selenium IDE,一个Firefox插件,可以在Firef ...
- undefined reference to `clock_gettime'编译错误的解决办法
解决办法如下
- Android Bitmap 缩放 旋转 水印 裁剪操作
在android当中,Bitmap代表一个图片,里面封装了图片相关的信息. 一.将图片进行缩放操作 1.获得Bitmap对象 Bitmap bitmap = BitmapFactory.decodeR ...
- USB入门
简述 USB(Universal Serial Bus)全称通用串口总线,USB为解决即插即用需求而诞生,支持热插拔.USB协议版本有USB1.0.USB1.1.USB2.0.USB3.1等,USB2 ...
- 【C】——sigprocmask 阻塞进程信号
1.有时候不希望在接到信号时就立即停止当前执行,去处理信号,同时也不希望忽略该信号,而是延时一段时间去调用信号处理函数.这种情况是通过阻塞信号实现的. 2.信号阻塞和忽略信号的区别. 阻塞的概念和忽略 ...
- java中unicode和中文相互转换
package test.com.gjob.services; import java.util.Properties; public class Test { public static void ...
- Servlet、Filter、Listener总结
servlet规范提供了一组标准的servlet api.servlet容器就是servlet规范的实现. 1.In Action (1)写一个类继承HttpServlet: (2)重写其中的方法. ...
- FreeRDP的安装配置(错误信息:SSL_read: Failure in SSL library (protocol error?))
最新文章:Virson's Blog 使用xfreerdp [serveripaddress]命令,连接xp/windows 2003都正常,但是在连接win7/2008时总是出错: ;------- ...