未加星标

wget和curl方式下载JDK

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

有时候我们需要在linux服务器上安装Oracle JDK,这时候我们发现直接复制网页上面的地址是不能下载的

以下载jdk-8u101-linux-i586.tar.gz为例,右键查看到的地址为http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-i586.tar.gz,但是这个地址并不能直接下载

通过浏览器开发工具观察我们发现,下载时经过了3次重定向才拿到最终的下载地址,并且Cookies中有个参数必须带上


wget和curl方式下载JDK

将这几个302跳转复制成curl观察一下

第一次重定向

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" --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"%"3A"%"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"第二次重定向

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"%"3A"%"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"第三次重定向

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"%"3A"%"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"真实下载

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"%"3A"%"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"其中真实下载地址中的AuthParam每次都会变化。

curl要通过-O参数才能下载文件,否则只是将内容输出到控制台。

所以curl方式的下载命令为

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

其中-L参数能够追踪重定向的地址,不加-L只能返回302的结果,cookies中有用的内容是同意协议那一部分,Connection: keep-alive这句要加上,否则下载速度会变成蜗牛

执行结果如下

[[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 Time Current

Dload Upload Total Spent Left Speed

8 174M 8 14.1M 0 0 404k 0 0:07:23 0:00:35 0:06:48 463k

同样的wget方式的下载命令为,wget的好处可以自动重定向,不用我们操心

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

其中 --no-check-certificate表示不校验SSL证书,因为中间的两个302会访问https,会涉及到证书的问题,不校验能快一点,影响不大,另一个--no-cookies表示不使用cookies,当然首次在header里指定的会带上,后面重定向的就不带了,这个影响也不大,可以不加。

[[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... 200 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

Linux wget命令详解 http://www.codesec.net/Linux/2012-08/67837.htm

Linux 下使用 wget/aria2 进行离线迅雷批量下载 http://www.codesec.net/Linux/2011-10/46052.htm

Linux使用wget请求地址时报错 http://www.codesec.net/Linux/2011-07/39345.htm

Linux下载命令wget使用详解 http://www.codesec.net/Linux/2011-01/30980.htm

wget 使用大全 http://www.codesec.net/Linux/2008-09/15722.htm

Linux 命令行下载工具 wget 的使用技巧 http://www.codesec.net/Linux/2007-10/8293.htm

wget 命令实例

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: LinuxWindows服务器浏览器迅雷UAFirefox
分页:12
转载请注明
本文标题:wget和curl方式下载JDK
本站链接:http://www.codesec.net/view/481298.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(37)