今天使用wget的方式在Linux上下载jdk-8u201-linux-x64.tar.gz,
wget https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_linux-x64_bin.tar.gz
下载完发现文件大小仅有5.2KB,
ls -lht -rw-r--r-- 1 root root 5.2K 3月 21 2012 jdk-15.0.1_linux-x64_bin.tar.gz
回过头细看下载信息,
--2021-01-02 19:23:19-- https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_linux-x64_bin.tar.gz 正在解析主机 download.oracle.com (download.oracle.com)... 88.221.164.33 正在连接 download.oracle.com (download.oracle.com)|88.221.164.33|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily 位置:https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_linux-x64_bin.tar.gz [跟随至新的 URL] --2021-01-02 19:23:21-- https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_linux-x64_bin.tar.gz 正在解析主机 edelivery.oracle.com (edelivery.oracle.com)... 92.122.87.84, 2600:1417:76:582::366, 2600:1417:76:594::366 正在连接 edelivery.oracle.com (edelivery.oracle.com)|92.122.87.84|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily 位置:http://download.oracle.com/errors/download-fail-1505220.html [跟随至新的 URL] --2021-01-02 19:23:23-- http://download.oracle.com/errors/download-fail-1505220.html 正在连接 download.oracle.com (download.oracle.com)|88.221.164.33|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 301 Moved Permanently 位置:https://download.oracle.com/errors/download-fail-1505220.html [跟随至新的 URL] --2021-01-02 19:23:24-- https://download.oracle.com/errors/download-fail-1505220.html 正在连接 download.oracle.com (download.oracle.com)|88.221.164.33|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:5307 (5.2K) [text/html] 正在保存至: “jdk-15.0.1_linux-x64_bin.tar.gz” 100%[============================================>] 5,307 --.-K/s 用时 0s 2021-01-02 19:23:25 (621 MB/s) - 已保存 “jdk-15.0.1_linux-x64_bin.tar.gz” [5307/5307])
查看最后几行,不难发现下载的其实是一个html失败页面https://download.oracle.com/errors/download-fail-1505220.html,最后保存到jdk-15.0.1_linux-x64_bin.tar.gz中。
发生失败的原因是Oracle对其资源的下载限制,那么如何wget下载jdk压缩包呢?
wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_linux-x64_bin.tar.gz OR wget --no-check-certificate -c --header="Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_linux-x64_bin.tar.gz
即给wget添加参数,使之跳过某些校验即可,具体可查询wget相关参数介绍,如下:
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.