Linux下wget方式下载jdk压缩包仅5KB的问题
今天使用wget的方式在Linux上下载jdk-8u201-linux-x64.tar.gz,
[root@192 ~]# wget https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
下载完发现文件大小仅有5.2KB,
[root@192 ~]# ls -lht jdk-8u201-linux-x64.tar.gz
-rw-r--r--. 1 root root 5.2K Mar 20 2012 jdk-8u201-linux-x64.tar.gz
回过头细看下载信息,
[root@192 ~]# wget https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
--2019-04-10 07:47:59-- https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)... 104.84.238.23
Connecting to download.oracle.com (download.oracle.com)|104.84.238.23|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz [following]
--2019-04-10 07:48:00-- https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
Resolving edelivery.oracle.com (edelivery.oracle.com)... 104.76.129.204, 2600:1406:1400:690::366, 2600:1406:1400:69d::366
Connecting to edelivery.oracle.com (edelivery.oracle.com)|104.76.129.204|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/errors/download-fail-1505220.html [following]
--2019-04-10 07:48:05-- http://download.oracle.com/errors/download-fail-1505220.html
Connecting to download.oracle.com (download.oracle.com)|104.84.238.23|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://download.oracle.com/errors/download-fail-1505220.html [following]
--2019-04-10 07:48:05-- https://download.oracle.com/errors/download-fail-1505220.html
Connecting to download.oracle.com (download.oracle.com)|104.84.238.23|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5307 (5.2K) [text/html]
Saving to: ‘jdk-8u201-linux-x64.tar.gz’
100%[==================================================================>] 5,307 --.-K/s in 0s
2019-04-10 07:48:06 (371 MB/s) - ‘jdk-8u201-linux-x64.tar.gz’ saved [5307/5307]
查看最后几行,不难发现下载的其实是一个html失败页面https://download.oracle.com/errors/download-fail-1505220.html,最后保存到jdk-8u201-linux-x64.tar.gz中。
发生失败的原因是Oracle对其资源的下载限制,那么如何wget下载jdk压缩包呢?
wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
OR
wget --no-check-certificate -c --header="Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
即给wget添加参数,使之跳过某些校验即可,具体可查询wget相关参数介绍,如下:
[root@192 ~]# wget -h
GNU Wget 1.14, a non-interactive network retriever.
Usage: wget [OPTION]... [URL]...
Mandatory arguments to long options are mandatory for short options too.
HTTPS (SSL/TLS) options:
--no-check-certificate don't validate the server's certificate.
Download:
-c, --continue resume getting a partially-downloaded file.
HTTP options:
-E, --header=STRING insert STRING among the headers.