cURL 重定向

  • curl获取Google,可以看出来命令本身不会跟踪重定向,得到302的状态
curl -s -f -I http://www.google.com
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.com.hk/?gfe_rd=cr&dcr=0&ei=bELsWaiZH4q_8QWqgLu4Bw
Content-Length: 272
Date: Sun, 22 Oct 2017 07:02:04 GMT
  • curl追踪重定向,使用-L
curl -s -f -I -L http://www.google.com
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: http://www.google.com.hk/?gfe_rd=cr&dcr=0&ei=c0LsWajsJZfB8AWch7HIBg
Content-Length: 272
Date: Sun, 22 Oct 2017 07:02:11 GMT

HTTP/1.1 200 OK
Date: Sun, 22 Oct 2017 07:02:11 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Big5
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2017-10-22-07; expires=Sun, 29-Oct-2017 07:02:11 GMT; path=/; domain=.google.com.hk
Set-Cookie: NID=114=srHUwtCAQUqg5q4WMblmeWFplXbpFPdvLsG33Fvqjpr3QNrqptNo-o0idqaLLI9H8kmFkeji5LVj9y4Stc99KQXIyPdo9w_SgEHhE4KtmOGfmxQk3Tm7pfob7W2Jl1Z6; expires=Mon, 23-Apr-2018 07:02:11 GMT; path=/; domain=.google.com.hk; HttpOnly
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding
  • Ref

curl follow redirects

你可能感兴趣的:(cURL 重定向)