事实上每个Unix系统都预装了curl命令。curl允许我们模拟任何HTTP请求,然而通过命令行方式下载文件和网页是它最常用的功能。
  Virtually every Unix system comes with the curl command pre-installed. curl allows us to simulate any HTTP request, although most commonly it’s used to download files and webpages from the command-line.
        下面是个小例子:
  Here’s a quick example:

$ curl http://google.com
<HTML><HEAD>
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF=”http://www.google.com/”>here</A>.
</BODY></HTML>
$

这里,curl抓取http://google.com的内容并打印输出任何我们收到的东西作为回应。这种情况下,我们收到一个让我们去往http://www.google.com的HTML文档。一般浏览器会自动跳转这个重定向,所以作为用户我们从不会看见这个页面。
  Here, curl is fetching the contents of http://google.com and printing out whatever we receive in response. In this case, we receive an HTML document telling us go to http://www.google.com instead. A normal browser would follow this redirect automatically, so as a user we’d never see this page.
        如果我们要求curl除了文本抓取其他东西,它仍会尝试将内容打印输出给终端,导致乱码。
  If we ask curl to fetch something other than text it will still try to print out its contents to the console, resulting in gibberish.

保存curl的输出
  Saving Output From curl

主要有两种方法保存curl输出:用>重定向或者加上 -o参数。
  There are two main ways to save the output from curl: using > redirection or using the -o option.

$ curl http://foo.com/bar.mp3 > song.mp3
$ curl -o song.mp3 http://foo.com/bar.mp3

这两个方法都使curl下载bar.mp3并将它写入当前目录下的song.mp3文件。
  Both of these will result in curl downloading bar.mp3 and writing it to the song.mp3 file in the current directory.

转载于:https://blog.51cto.com/smellyman/1891034

使用curl创建HTTP请求 Using curl To Make HTTP Requests--用Enki学Linux系列(3)相关推荐

  1. curl跨服务器请求文件,Curl上传文件的服务器API POST调用

    我想将一系列POSTMAN调用翻译成bash以创建脚本.超级简单到现在,我要发布与形式,data.I角色的XLSX文件中使用这个脚本:Curl上传文件的服务器API POST调用 curl -i -X ...

  2. nodejs实践录:使用curl测试post请求

    以前与后台交互的json接口,都是用postman工具来测试的,后来发现curl命令也可以发post或get请求.本文利用koa创建web服务器,对外提供了几个URL,然后用curl进行测试. 3.源 ...

  3. curl进行post请求的demo

    这边主要是记录一下curl的post请求.在某些应用场景,我们必须通过post方式访问别人给的接口.针对这种情况,个人感觉curl是最合适的. demo: $curl = curl_init();// ...

  4. 用curl发起https请求

    使用curl发起https请求 使用curl如果想发起的https请求正常的话有2种做法: 方法一.设定为不验证证书和host. 在执行curl_exec()之前.设置option $ch = cur ...

  5. php curl发送post请求失败,PHP中的使用curl发送请求(GET请求和POST请求)

    使用CURL发送请求的基本流程 使用CURL的PHP扩展完成一个HTTP请求的发送一般有以下几个步骤: 1.初始化连接句柄: 2.设置CURL选项: 3.执行并获取结果: 4.释放VURL连接句柄. ...

  6. 【Linux】一步一步学Linux——curl命令(193)

    00. 目录 文章目录 00. 目录 01. 命令概述 02. 命令格式 03. 常用选项 04. 参考示例 05. 附录 01. 命令概述 curl命令是一个利用URL规则在shell终端命令行下工 ...

  7. curl模拟post请求

    另外可尝试 postman工具 或者用request 直接请求 CURL 发送POST请求curl -header "Content-Type: application/json" ...

  8. PHP爬取post网页数据,php curl发送post请求爬取webService接口数据简单实例

    header('Content-Type: text/html;charset=utf-8'); /** * 使用curl发送post请求 * @param $url * @param string ...

  9. linux curl 命令 http请求、下载文件、ftp上传下载

    1. curl 命令简介 cURL(CommandLine Uniform Resource Locator),是一个利用 URL 语法,在命令行终端下使用的网络请求工具,支持 HTTP.HTTPS. ...

最新文章

  1. 公路修建问题(二分+最小生成树)
  2. javascript 两个数组组成一个对象
  3. Tomcat 修改JSESSIONID
  4. MCS-51单片机的指令时序
  5. Why with_indobjects is not available in product search
  6. lassAtitit事件代理机制原理 基于css class的事件代理的事件代理titi
  7. 装机软件五:截图工具
  8. Bluetooth基础知识--蓝牙的几种通讯方式
  9. IBM服务器无法启动怎么恢复
  10. 原生js获取元素非行内样式属性的方法
  11. 性能测试培训:性能瓶颈分析思路
  12. HTML5手机页面触屏滑动上下翻页特效
  13. 神秘鸭,让语音操作电脑不再神秘 小爱同学
  14. Paddle2ONNX最新升级:飞桨模型全面支持ONNX协议啦!
  15. Kejin Player (概率DP)hdu6656
  16. matlab 模拟风,【Matlab实现】风场仿真
  17. 基于华为云原生数据湖MRS HetuEgine的数据虚拟化实践
  18. JavaScript小技能:客户端 API
  19. OKHttp请求访问-同步-JSON-添加请求头参数
  20. 回击MLAA:NVIDIA FXAA抗锯齿性能实測、画质对照

热门文章

  1. 一个很精致的HelloWorld,你看得懂么?
  2. resizeEvent , paintEvent事件触发原因
  3. 经典的股票量化交易策略(含源码)
  4. android如何获取网络的状态码,Android RxJava+Retrofit网络异常、状态码统一处理
  5. img标签 src路径正确 但图片不显示
  6. 椭圆机的减肥效果怎么样
  7. 哈尔滨工业大学计算机考研难吗,哈尔滨工业大学(专业学位)计算机技术考研难吗...
  8. 盘点测试分析工具资源,文章教程/视频教程等你来体验!
  9. 利用zxing生成二维码
  10. Ubuntu18.04安装sagemath(命令行安装,超方便)