curl and wget

写在前面:

a.  对比curl 和 wget 的相同和不同点 来记忆

 

a-1

curl url  直接将请求内容输出到标准输出。 如果下载不是瞬时间完成,会显示下载进度条,如果向取消,加-s :

wget  url 将请求内容下载到当前目录,名字是请求的文件名字。同时会显示域名解析 和 端口连接信息,如果想屏蔽,加 -q :

a-2

curl 请求常用 -Lvso   -o  将请求内容输出到指定文件, -L follow 301 and 302 , -v 输出请求头和响应头信息。

wget 请求常用 -SO -O 将请求内容输出到指定文件 , -S 打印响应头。curl 不能实现 输出响应头信息的同时将请求内容下载下来, 只能实现  输出HTTP头和返回内容 ,用 -i 参数。

a-3

curl -I  and -i  区别, -I 只输出响应头信息,不返回请求内容, -i 输出HTTP头和返回内容。

 

curl and wget 详细的命令,如下

1. curl  

直接跟 url ,会将url 的内容直接输出到桌面,同时会显示下载进度条, -s 可屏蔽这个输出

-s silent   -v 详细输出   -L  302 追踪

-w  自定义输出格式  如 

 -w %{http_code} 

 curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n

%{time_total}--%{time_namelookup}--%{time_connect}--%{time_appconnect}--%{time_pretransfer}--%{time_starttransfer}--%{speed_download}"\n" 

 

-x 代理

-I 只输出请求header , -i  include  请求内容和  header

-A  自定义user-agent

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

-H  自定义header

默认请求内容输出到屏幕 , -o 输出重定向, 可以直接请求https

 

curl 的post 请求,

curl  只跟 -d  或--data  ,代表是post 请求, -X POST 可加可不加,post 请求 也是有返回内容的(不是我以前自认为的理解 无返回内容),如果请求的格式是json 格式,即  ”Content_Type:Application/json “,返回的是json字符串,想要 直观的查看字符串的内容,要将字符串 转换成json 格式化,网上搜索 json格式化 即可。

-d POST 请求发送 json 数据, 如

curl -H "Content-type:Application/json" -d '{"hostname": "a-1-1", "result": {"hostname": "hostname", "network": [{"DEVICE": "bond0", "IPADDR": "1.1.1.1"}, {"DEVICE": "bond1", "IPADDR": "10.11.100.32"}], "service_tag": "060580bD40"}}'  "url"

 

 

https 访问加代理方式  --resolv blog.csdn.net:443:47.95.47.253

 

curl 组合使用命令  

-Lvo /dev/null    访问内容输出到 /dev/null  -o 访问结果 输出详情 -v   follow 第三方跳转 -L

-s  访问结果silence ,传输速度 不输出,curl 默认显示传输速度

--limit-rate number   限速,可以识别单位,不加单位默认是 比特, B  ,不是 b 字节。

 

wget 参数

wget -SO /dev/null http://www.jd.com -e http-proxy=1.1.1.1 --limit-rate=100   

-O 下载内容输出位置,默认输出到当前目录,名字为url 的文件名,-O 自定义名字

-S  print server response

-q  quite

--limit-rate=1K   限速 1KB/s, 和 curl 限速一样,不加单位,默认是B,字节,不是b,比特,命令和curl 区别是  curl 无=  wget 跟 = 

 -O 跟- 代表下载内容输出到 stand output ,同 curl 默认输出,多用于 直接执行下载脚本内容。如 wget -qO - http://url/a.sh |bash 

--header  请求头 

-e http-proxy=

 

curl 如何访问ipv6 地址:

提示: 将ipv6 地址 放到 [] 里, 其他语法照旧:

如:curl "http://[2409:8c44:2f00:300:8001::239]:80/m.html"

”“  加不加 无所谓

 

curl 报错  curl: (3) [globbing] error: bad range specification after pos 9

解决办法: 加  -g  :

-g/--globoff
 This  option  switches off the "URL globbing parser". When you set this option, you can specify URLs that contain the letters {}[] without having them being interpreted by curl itself. Note that these letters are not normal legal
 URL contents but they should be encoded according to the URI standard.
翻译:

 -g/  --globoff 通配符关闭  globbing 通配符

这个选项 是 关闭  “URL 通配符 解析” 。当你设置了此参数,你就可以指定 那些包含 字符 {} 和 [] 的 URL 不用翻译这些字符(即不把这两个字符当通配符对待)。注意 这些字符 并不是 正常合法的URL 包含的,但它们 应当被 依据 URI 标准 被 编码。

 

posted @ 2019-06-19 15:32  BRUCECSDN  阅读(408)  评论(0)    收藏  举报