linux命令行下载jdk

时间:2021-07-04 15:29:19

官网JDK7下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

在里面有各种系统的JDK,我下载的是linux x64的rpm格式。

命令 wget -c -P /root/Downloads http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm

但是该命令会现一个use'--no-check-certificate'的错误提示,网上查是由于https证书造成,于下把命令改成如下:

wget -c -P /root/Downloads --no-check-certificate http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm

提示下载成功,但是下载下来的并不是我要的121M的rpm文件,而是一个5k的html文件,这是什么原因呢,于是我直接把

http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm放在本地的浏览器上下载,同样出现了一个提示cookies不正常的HTML页面。

此时我意识到是cookie的防盗链造成,于是我在本地打开fidder浏览器监视软件,浏览器进入http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html,然后点击下载连接,在fidder中查看该连接的cookie为s_nr=1420682671945; s_cc=true; oraclelicense=accept-securebackup-cookie; gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk7-downloads-1880260.html; s_sq=%5B%5BB%5D%5D

于是我再次把命令改成:

wget -c -P /root/Downloads --no-check-certificate --no-cookie --header "Cookie: s_nr=1420682671945; s_cc=true; oraclelicense=accept-securebackup-cookie; gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk7-downloads-1880260.html;s_sq=%5B%5BB%5D%5D" http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm

OK,能正确下载到rpm了