zoukankan      html  css  js  c++  java
  • Linux curl


    注 curl 一个url时 最好对url加上引号(单双都行),如果中间有{}符号 应对其转义 { } 否则会报 nested braces not supported 不支持嵌套的括号

    1) 最简单的使用

    $ curl http://www.linuxidc.com

    2) 把读过来页面存下来

    $ curl http://www.linuxidc.com > page.html

    也可以用option: -o

    $ curl -o page.html http://www.linuxidc.com

    3) 指定http访问所使用的proxy服务器及其端口: -x

    $ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

    4) 把http的response里面的cookie信息存到一个特别的文件中去

    $ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

    5)继续使用上次留下的cookie信息,我们上次的cookie信息追加到http request里面去: -b

    $ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

    6)指定自己访问所宣称的自己的浏览器信息: -A

    $ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

    7)模拟检查http访问的referer option: -e

    $ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com

    8)option: -O 大写的O

    $ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG

    就可以按照服务器上的文件名,自动存在本地了!

    再来一个更好用的。

    如果screen1.JPG以外还有screen2.JPG、screen3.JPG、....、screen10.JPG需要下载

    $ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG

    9)下载防止重名

    $ curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG

    原来: ~zzh/001.JPG —-> 下载后: 001-zzh.JPG 原来: ~nick/001.JPG —-> 下载后: 001-nick.JPG

    $ curl ftp://name:passwd@ip:port/path/file

    10) 上传的option是 -T 我们向ftp传一个文件:

    $ curl -T localfile -u name:passwd ftp://upload_site:port/path/

    向http服务器上传文件也可以比如

    $ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi

    POST模式下的文件上的文件上传,比如

    <form method="POST" enctype="multipar/form-data" action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi">

    <input type=file name=upload>

    <input type=submit name=nick value="go">

    </form>

    这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:

    $ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

    https的时候使用本地证书

    $ curl -E localcert.pem https://remote_server


    curl post 提交 xml
    curl -i –k 'https://api.dev.hotwire.com/v3/secure/booking/hotel?apikey=bqh3bv4ugfjk5swpcwn74w32&sig='$(php -r 'echo hash("sha256", "bqh3bv4ugfjk5swpcwn74w32test123456".time());') -H 'Content-type: text/xml' -d @dev-booking_request_credit_card.xml -X POST

    获取头信息 -i  
    curl -s -i "http://www.baidu.com" | awk '/HTTP/ {print $2}'

    Authorization验证
    curl -X POST -H "Authorization:$(php -r "echo 'Basic '.base64_encode('GEDAI:xauN7HX86WaHJ14i');")" -H "Content-Type: application/json" -k http://api.bdp.com/spider/billdetail -d '{"params":{"account":"13584845491","type":"YYS"}}'
    等同于 -u GEDAI:xauN7HX86WaHJ14i 参数
    curl -X POST -u GEDAI:xauN7HX86WaHJ14i -H "Content-Type: application/json" -k http://api.bdp.com/spider/billdetail -d '{"params":{"account":"18388450547","type":"YYS"}}'

     curl  -H "client-ip:1.2.3.5" -H "x-forwarded-for:1.2.3.5" http://localhost:8080/index.php 伪造ip

    //绑定hosts

    curl --silent -H "Host: www.zggo.com" "192.168.0.1/xxx/xxx/db.error.log"

  • 相关阅读:
    Python 安装Twisted 提示python version 2.7 required,which was not found in the registry
    Openfire Strophe开发中文乱码问题
    css div 垂直居中
    How to create custom methods for use in spring security expression language annotations
    How to check “hasRole” in Java Code with Spring Security?
    Android 显示/隐藏 应用图标
    Android 当媒体变更后,通知其他应用重新扫描
    文件上传那些事儿
    专题:点滴Javascript
    主流动画实现方式总结
  • 原文地址:https://www.cnblogs.com/wangxusummer/p/6490811.html
Copyright © 2011-2022 走看看