linux curl命令详解及实例分享

2019-10-14 13:24:44丽君

  -Y/--speed-limit 停止传输速度的限制,速度时间'秒

  -z/--time-cond  传送时间设置

  -0/--http1.0  使用HTTP 1.0

  -1/--tlsv1  使用TLSv1(SSL)

  -2/--sslv2 使用SSLv2的(SSL)

  -3/--sslv3         使用的SSLv3(SSL)

  --3p-quote      like -Q for the source URL for 3rd party transfer

  --3p-url        使用url,进行第三方传送

  --3p-user       使用用户名和密码,进行第三方传送

  -4/--ipv4   使用IP4

  -6/--ipv6   使用IP6

  -#/--progress-bar 用进度条显示当前的传送状态

  二,常用curl实例

  1,抓取页面内容到一个文件中

  [root@krlcgcms01 mytest]# curl -o home.html  //www.jb51.net

  [root@krlcgcms01 mytest]# curl -o home.html  //www.jb51.net

  2,用-O(大写的),后面的url要具体到某个文件,不然抓不下来。我们还可以用正则来抓取东西

  [root@krlcgcms01 mytest]# curl -O

  [root@krlcgcms01 mytest]# curl -O

  3,模拟表单信息,模拟登录,保存cookie信息

  [root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** //www.jb51.net/wp-login.php

  [root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** //www.jb51.net/wp-login.php

  4,模拟表单信息,模拟登录,保存头信息

  [root@krlcgcms01 mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** //www.jb51.net/wp-login.php

  [root@krlcgcms01 mytest]# curl -D ./cookie_D.txt -F log=aaaa -F pwd=****** //www.jb51.net/wp-login.php

  -c(小写)产生的cookie和-D里面的cookie是不一样的。

  5,使用cookie文件

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt  //www.jb51.net/wp-admin

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt  //www.jb51.net/wp-admin

  6,断点续传,-C(大写的)

  [root@krlcgcms01 mytest]# curl -C -O

  7,传送数据,最好用登录页面测试,因为你传值过去后,curl回抓数据,你可以看到你传值有没有成功

  [root@krlcgcms01 mytest]# curl -d log=aaaa  //www.jb51.net/wp-login.php

  [root@krlcgcms01 mytest]# curl -d log=aaaa  //www.jb51.net/wp-login.php

  8,显示抓取错误,下面这个例子,很清楚的表明了。

  [root@krlcgcms01 mytest]# curl -f //www.jb51.net/asdf

  curl: (22) The requested URL returned error: 404

  [root@krlcgcms01 mytest]# curl //www.jb51.net/asdf

  <HTML><HEAD><TITLE>404,not found</TITLE>

  。。。。。。。。。。。。

  [root@krlcgcms01 mytest]# curl -f //www.jb51.net/asdf