# 以下操作可以挂代理抓包查看并且验证
# -v 通过使用 -v 和 -trace获取更多的链接信息
# 访问https://www.github.com/下面返回的信息会提示该域名已经被重定向到https://github.com/
$ curl -v "https://www.github.com/"
* Rebuilt URL to: https://www.github.com/
* Hostname was NOT found in DNS cache
* Trying 192.30.252.130...
* Connected to www.github.com (192.30.252.130) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: github.com
* Server certificate: DigiCert SHA2 Extended Validation Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: www.github.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: https://github.com/
< Connection: close
<
* Closing connection 0
# -A 设置http请求头User-Agent,可以指定自己这次访问所模拟的浏览器信息
# 前一个直接用curl命令的,User-Agent: curl/7.37.1
> User-Agent: curl/7.37.1
# 使用-A参数重新指定浏览器信息后,User-Agent: Mozilla/5.0 Firefox/21.0
> User-Agent: Mozilla/5.0 Firefox/21.0
$ curl -v -A "Mozilla/5.0 Firefox/21.0" "https://www.github.com/"
Hostname was NOT found in DNS cache
* Trying 192.30.252.120...
* Connected to www.github.com (192.30.252.120) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: github.com
* Server certificate: DigiCert SHA2 Extended Validation Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> GET / HTTP/1.1
> User-Agent: Mozilla/5.0 Firefox/21.0
> Host: www.github.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: https://github.com/
< Connection: close
<
* Closing connection 0
# -e 设置http请求头Referer,解释:检查http访问的Referer是服务器端常用的限制方法。比如你先访问网站的首页,再访问里面所指定的下载页,这第二次访问的referer地址就是第一次访问成功后的页面地址。这样,服务器端只要发现对下载页面某次访问的referer地址不是首页的地址,就可以断定那是个盗链了。所以这里我们可以自己修改我们的Referer链接地址。
$ curl -v -e "http://birdben.com/" "http://birdben.com/download.html"
* Hostname was NOT found in DNS cache
* Trying 50.63.202.46...
* Connected to birdben.com (50.63.202.46) port 80 (#0)
> GET /download.html HTTP/1.1
> User-Agent: curl/7.37.1
> Host: birdben.com
> Accept: */*
> Referer: http://birdben.com/
>
< HTTP/1.1 302 Found
< Connection: close
< Pragma: no-cache
< cache-control: no-cache
< Location: /download.html
<
* Closing connection 0
# --header/-H 设置header
$ curl -H "Connection:keep-alive" -H "Host:127.0.0.1" -H "Accept-Language:es" -H "Cookie:ID=1234" "https://www.github.com/"
* Hostname was NOT found in DNS cache
* Trying 192.30.252.129...
* Connected to www.github.com (192.30.252.129) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: github.com
* Server certificate: DigiCert SHA2 Extended Validation Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Accept: */*
> Connection:keep-alive
> Host:127.0.0.1
> Accept-Language:es
> Cookie:ID=1234
>
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: https://github.com/
< Connection: close
<
* Closing connection 0
# -I 设置http响应头处理,仅仅返回header
$ curl -I "https://github.com"
# --dump-header/-D 将http header保存到/tmp/header文件
$ curl -D /tmp/header "https://github.com"