Sometimes we need to install Oracle JDK on the server, when we find that the address directly above the copy page is not downloadable.
To download jdk-8u101-linux-i586.tar.gz as an example, right-click to see the address is http://download.oracle.com/otn-pub/java/jdk/8u101-b13/ Jdk-8u101-linux-i586.tar.gz, but this address cannot be downloaded directly
Through the browser development tool, we found that the download was 3 redirects to get the final, and the cookies have a parameter must be brought
Copy these 302 jumps into curl to see
Redirect for the first time
curl "http://download.oracle.com/otn-pub/java/jdk/8u101-b13/ Jdk-8u101-linux-i586.tar.gz "
-h" Host:download.oracle.com "-H" user-agent: mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:47.0) gecko/20100101 firefox/47.0 "
-h" accept:text/html,application/ xhtml+xml,application/xml;q=0.9,*/*;q=0.8 "-H" accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 "
Span style= "COLOR: #000000" >--compressed-h "referer:http://www.oracle.com/technetwork/java/javase/downloads/ Jdk8-downloads-2133151.html "
-h" cookie:s_nr=1472257078143; eloqua=guid=e0964a7736384dc98085509e60e04539; S_cc=true; Gpw_e24=http "%" 3 A "%" 2F "%" 2fwww.oracle.com "%" 2Ftechnetwork "%" 2Fjava "%" 2Fjavase "%" 2Fdownloads "%" 2fjdk8-downloads-2133151.html;
s_sq= "%" 5B "%" 5BB "%" 5D "%" 5 D; Oraclelicense=accept-securebackup-cookie "-H" connection:keep-alive "
Second redirect
Curl "https://edelivery.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz"-H "Host: Edelivery.oracle.com "-H" user-agent:mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:47.0) gecko/20100101 firefox/47.0 "-H" accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 "- H "accept-language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3"--compressed-h "referer:http://www.oracle.com/technetwork /java/javase/downloads/jdk8-downloads-2133151.html "-H" cookie:aru_lang=us; s_nr=1472257078143; eloqua=guid=e0964a7736384dc98085509e60e04539; S_cc=true; Gpw_e24=http "%" 3 A "%" 2F "%" 2fwww.oracle.com "%" 2Ftechnetwork "%" 2Fjava "%" 2Fjavase "%" 2Fdownloads "%" 2fjdk8-downloads-2133151.html; s_sq= "%" 5B "%" 5BB "%" 5D "%" 5 D; Oraclelicense=accept-securebackup-cookie "-H" connection:keep-alive "third redirect"
curl "https://edelivery.oracle.com/osdc-otn/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz" -h "host: edelivery.oracle.com" -H "user-agent: mozilla/5.0 (windows nt 6.3; win64; x64; rv:47.0) gecko/20100101 firefox/47.0 " -H " Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 " -H " accept-language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 " --compressed -H " referer: http://www.oracle.com/ Technetwork/java/javase/downloads/jdk8-downloads-2133151.html " -H " Cookie: aru_lang=us; s_ Nr=1472257078143; eloqua=guid=e0964a7736384dc98085509e60e04539; s_cc=true; gpw_e24=http "%" 3 A "%" 2F "%" 2fwww.oracle.com "%" 2Ftechnetwork "%" 2Fjava "%" 2Fjavase "%" 2Fdownloads "%" 2fjdk8-downloads-2133151.html; s_sq= "%" 5B "%" 5BB "%" 5D "%" 5d; oraclelicense=accept-securebackup-cookie " -H " connection: Keep-alive "
Live Download
curl "Http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz? Authparam=1472300350_2a4acf9c53c18478db4839cbf7ec69c6 " -H " host: download.oracle.com " -H "user-agent: mozilla/5.0 (windows nt 6.3; win64; x64; rv:47.0) gecko/20100101 firefox/47.0 " -H " accept: text/html,application/xhtml+xml,application/xml;q =0.9,*/*;q=0.8 " -H " accept-language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 " --compressed -H "referer: http://www.oracle.com/technetwork/java/javase/downloads/ Jdk8-downloads-2133151.html " -H " cookie: s_nr=1472257078143; eloqua=guid= E0964a7736384dc98085509e60e04539; s_cc=true; gpw_e24=http "%" 3 A "%" 2F "%" 2fwww.oracle.com "%" 2Ftechnetwork "%" 2Fjava "%" 2Fjavase "%" 2Fdownloads "%" 2fjdk8-downloads-2133151.html; s_sq= "%" 5B "%" 5BB "%" 5D "%" 5d; oraclelicense=accept-securebackup-cookie " -H " connection: keep-Alive "
The real authparam change every time.
Curl can download the file through the-o parameter, or it simply outputs the content to the console.
So the curl mode of the download command is
Curl-l "Http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz"
-H "Cookie:oraclelicense=accept-securebackup-cookie"-H "connection:keep-alive"-O
Where the-l parameter can trace the redirected address, no-L can only return 302 of the results, the useful content of the cookie is the consent agreement that part, connection:keep-alive this sentence to add, otherwise the download speed will become a snail
Execution results are as follows
- [Email protected] ~]# curl-l "http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz"- H "Cookie:oraclelicense=accept-securebackup-cookie"-H "connection:keep-alive"-O
- % total% Received% xferd Average speed Time Time current
- Dload Upload Total spent
- 8 174M 8 14.1M 0 0 404k 0 0:07:23 0:00:35 0:06:48 463k
The same wget way of downloading commands for, wget benefits can be automatically redirected without us worrying about
wget--no-check-certificate--no-cookies--header "Cookie:oraclelicense=accept-securebackup-cookie"/HTTP/ Download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz
Where--no-check-certificate means that the SSL certificate is not verified, because the middle of the two 302 will access HTTPS, will be related to the issue of certificates, not check can be faster, the impact is not small, another--no-cookies means not to use cookies, Of course, the first time in the header designated will take, the back of the redirect is not brought, this effect is not big, can not add.
- [Email protected] downloads]# wget--no-check-certificate--no-cookies--header "cookie:oraclelicense= Accept-securebackup-cookie "http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz
- --2016-08-27 20:47:52--http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz
- Resolving download.oracle.com ... 206.160.170.51, 206.160.170.9
- Connecting to download.oracle.com|206.160.170.51|:80 ... Connected.
- HTTP request sent, awaiting response ... 302 Moved temporarily
- location:https://edelivery.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz [following]
- --2016-08-27 20:47:52--https://edelivery.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz
- Resolving edelivery.oracle.com ... 60.254.134.143
- Connecting to edelivery.oracle.com|60.254.134.143|:443 ... Connected.
- HTTP request sent, awaiting response ... 302 Moved temporarily
- location:https://edelivery.oracle.com/osdc-otn/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz [ Following]
- --2016-08-27 20:47:53--https://edelivery.oracle.com/osdc-otn/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz
- Reusing existing connection to edelivery.oracle.com:443.
- HTTP request sent, awaiting response ... 302 Moved temporarily
- Location:http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz? authparam=1472302193_c5af865490ac9f21f2605a3abee94745 [following]
- --2016-08-27 20:47:53--http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz? authparam=1472302193_c5af865490ac9f21f2605a3abee94745
- Connecting to download.oracle.com|206.160.170.51|:80 ... Connected.
- HTTP request sent, awaiting response ... OK
- length:183456778 (175M) [Application/x-gzip]
- Saving to: "Jdk-8u101-linux-i586.tar.gz.1"
- 2% [==>] 4,740,512 863k/s ETA 4m 40s
Reference Link: http://blog.csdn.net/gsls200808/article/details/52336745
wget and Curl Download JDK