• Curl -------你应该知道的一些知识


    what is curl

    cURL是一个利用URL语法在命令行下工作的文件传输工具,1997年首次发行。它支持文件上传和下载,所以是综合传输工具,但按传统,习惯称cURL为下载工具。cURL还包含了用于程序开发的libcurl。

    References[百度百科]

    What's curl used for?

    获得页面

    curl http://curl.haxx.se

    常用参数

    如果下载的是HTML文档,那么缺省的将只显示文件头部,即HTML文档的header。

    要全部显示,请加参数 -i, 要只显示头部,用参数 -I(大写i)。

    任何时候,可以使用-v命令看curl是怎样工作的,它向服务器发送的所有命令都会显示出来。

    为了断点续传,可以使用-r参数来指定传输范围。

    获取表单

    get
    <form method="GET" action="junk.cgi">
    <input type=text name="birthyear">
    <input type=submit name=press value="OK">
    </form>

    那么浏览器上会出现一个文本框和一个标为“OK”的按钮。按下这个按钮,表单就用GET方法向服务器提交文本框的数据。 例如原始页面是在 www.hotmail. com/when/birth.html看到的,然后您在文本框中输入1905,然后按OK按钮,那么浏览器的URL现在应该是:“www.hotmail. com/when/junk.cgi?birthyear=1905&press=OK” 对于这种网页,curl可以直接处理,例如想获取上面的网页,只要输入:

    curl "www.hotmail. com/when/junk.cgi?birthyear=1905&press=OK"
    post
    <form method="POST" action="junk.cgi">
    <input type=text name="birthyear">
    <input type=submit name=press value="OK">
    </form>

    浏览器上也会出现一个文本框和一个标为“OK”的按钮。按下这个按钮,表单用POST方法向服务器提交数据。 这时的URL是看不到的,因此需要使用特殊的方法来抓取这个页面:

    curl -d "birthyear=1905&press=OK" www.hotmail. com/when/junk.cgi
    post本地文件

    将本地的文件用POST上传到服务器。

    <form method="POST" enctype='multipart/form-data' action="upload.cgi">
    <input type=file name=upload>
    <input type=submit name=press value="OK">
    </form>

    仅需要执行以下

    curl -F upload=@localfilename -F press=OK URL

    指定用户端

    有些网络资源首先需要判断用户使用的是什么浏览器,符合标准了才能够下载或者浏览。此时curl可以把自己“伪装”成任何其他浏览器:

    curl -A "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" URL

    这个指令表示curl伪装成了IE5.0,用户平台是Windows 2000。(对方服务器是根据这个字串来判断客户端的类型的,所以即使使用AIX也无所谓)。

    有关认证

    curl可以处理各种情况的认证页面,例如下载用户名/密码认证方式的页面(在IE中通常是出现一个输入用户名和密码的输入框):

    curl -u name:password www.secrets.com

    如果网络是通过http代理服务器出去的,而代理服务器需要用户名和密码,那么输入:

    curl -U proxyuser:proxypassword http://curl.haxx.se

    任何需要输入用户名和密码的时候,只在参数中指定用户名而空着密码,curl可以交互式的让用户输入密码。

    how to use curl

    curl --help 常用参数如下
     -I, --head          Show document info only
     --no-sessionid  Disable SSL session-ID reusing
     -i, --include       Include protocol response headers in the output
     -T, --upload-file <file> Transfer local FILE to destination
         --url <url>     URL to work with
     -B, --use-ascii     Use ASCII/text transfer
     -u, --user <user:password> Server user and password
     -A, --user-agent <name> Send User-Agent <name> to server
     -v, --verbose       Make the operation more talkative
     -V, --version       Show version number and quit
     -w, --write-out <format> Use output FORMAT after completion
         --xattr         Store metadata in extended file attributes

    https://en.wikipedia.org/wiki/CURL References[wikipedia]

    how to download&install curl

    curl命令安装使用(以windows为例)

    1、下载 https://skanthak.homepage.t-online.de/curl.html#download 或者https://curl.haxx.se/download/?C=M;O=D 选择较新的版本curl-7.64.0.cab

    2、解压 解压后路径,如E:安装包管理curl-7.64.0I386CURL.EXE

    3、验证 命令行切换到E:安装包管理curl-7.64.0I386 目录下执行curl --help 若可以输出参数即安装成功

    4、配置环境 如果想要在DOS窗口中任意位置使用curl命令,将解压下载好的文件,拷贝I386/curl.exe文件到C:WindowsSystem32即可

  • 相关阅读:
    ActiveMq主从机制
    Calling handler.OnEndpointsUpdate报错原因
    【Android Studio安装部署系列】二十二、Android studio自动生成set、get方法
    【Android Studio安装部署系列】二十一、Android studio将项目上传到github中
    【Android Studio安装部署系列】二十、Android studio如何将so文件添加到svn中
    【Android Studio安装部署系列】十九、Android studio使用SVN
    【Android Studio安装部署系列】十八、Android studio更换APP应用图标
    【Android Studio安装部署系列】十七、Android studio引用第三方库、jar、so、arr文件
    【Android Studio安装部署系列】十六、Android studio在layout目录下新建子目录
    【Android Studio安装部署系列】十五、Android studio添加Assets目录
  • 原文地址:https://www.cnblogs.com/echoqi/p/10575875.html
Copyright © 2020-2023  润新知