美文网首页
curl命令详解

curl命令详解

作者: supermanto | 来源:发表于2020-04-06 10:10 被阅读0次

在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具。它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具。

语法: curl [option] [url]

常见参数:

-A/--user-agent <string> 设置用户代理发送给服务器
-b/--cookie <name=string/file> cookie字符串或文件读取位置
-c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中
-C/--continue-at <offset> 断点续转
-D/--dump-header <file> 把header信息写入到该文件中
-e/--referer 来源网址
-f/--fail 连接失败时不显示http错误
-o/--output 把输出写到该文件中
-O/--remote-name 把输出写到该文件中,保留远程文件的文件名
-r/--range <range> 检索来自HTTP/1.1或FTP服务器字节范围
-s/--silent 静音模式。不输出任何东西
-T/--upload-file <file> 上传文件
-u/--user <user[:password]> 设置服务器的用户和密码
-w/--write-out [format] 什么输出完成后
-x/--proxy <host[:port]> 在给定的端口上使用HTTP代理
-#/--progress-bar 进度条显示当前的传送状态
-I 只展示基础信息(响应头)

例子:
1 基础用法:

Administrator@PC-20141114NHWZ MINGW64 /e/shell/file_folder
$ curl  https://testing-studio.com/

可以看到该页面的html代码打印在屏幕上
2 可以将html代码输出到文件中

Administrator@PC-20141114NHWZ MINGW64 /e/shell/file_folder
$ curl  https://testing-studio.com/ > testing.html
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17229    0 17229    0     0  39156      0 --:--:-- --:--:-- --:--:-- 39246

可以看到,目录下新增了文件testing.html

3 将html代码追加到某个文件中

Administrator@PC-20141114NHWZ MINGW64 /e/shell/file_folder
$ curl  https://testing-studio.com/ >> testing.html
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17229    0 17229    0     0  15748      0 --:--:--  0:00:01 --:--:-- 15763

可以看到testing.html又追加了内容
4 过滤该页面的所有超链接

Administrator@PC-20141114NHWZ MINGW64 /e/shell/file_folder
$ curl  https://testing-studio.com/ | grep href > filtering.txt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17229    0 17229    0     0  58206      0 --:--:-- --:--:-- --:--:-- 58403
可以看到把所有的href都过滤出来了

5 -I可以查看响应头信息

Administrator@PC-20141114NHWZ MINGW64 /e/shell/file_folder
$ curl -s -I https://testing-studio.com/
HTTP/2 200
server: nginx
date: Sat, 22 Feb 2020 06:58:34 GMT
content-type: text/html; charset=utf-8
vary: Accept-Encoding
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-download-options: noopen
x-permitted-cross-domain-policies: none
referrer-policy: strict-origin-when-cross-origin
x-discourse-route: list/latest
cache-control: no-cache, no-store
x-request-id: 43d9067e-4b9b-4e98-8b6b-966516d0452f
x-runtime: 0.059283
strict-transport-security: max-age=31536000

6 发送一个GET请求

--- ~ » curl -X GET url -H 'cookie:xxxx'

7 发送一个POST请求

--- ~ » curl -X POST url -H 'cookie:xxxx' -d ''

相关文章

  • curl命令详解

    linux命令之curl curl命令详解 1、curl命令简介 curl命令是一个利用URL规则在命令行下工作的...

  • shell调用kylo API

    参考:curl命令详解 yum install -y jq

  • Linux curl

    Linux curl命令详解 命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工...

  • curl 命令工具的使用

    curl 命令详解 curl的命令全称是client url 就是模仿客户端访问url的一种命令行方式,比较方便快...

  • CURL的使用详解

    CURL的使用详解 发起GET请求 命令后直接跟地址curl 'https://www.baidu.com' 请求...

  • 7.CURL命令的基本使用

    curl 命令详解~~ 直接在 curl 命令后加上网址,就可以看到网页源码 网页保存下来,可以使用 -o 参数 ...

  • curl 命令详解

    [TOC] 常用参数详解 常用curl实例 抓取页面内容到一个文件中 用 -O(大写的),后面的url要具体到某个...

  • curl 命令详解

    curl命令 网络应用 curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以...

  • curl命令详解

    介绍 curl(CommandLine Uniform Resource Locator),即在命令行中利用URL...

  • Curl命令详解

    本文转载自curl 的用法指南-阮一峰 简介   curl 是常用的命令行工具,用来请求 Web 服务器。它的名字...

网友评论

      本文标题:curl命令详解

      本文链接:https://www.haomeiwen.com/subject/xddlqhtx.html