java—在批处理文件中下载带有wget的jdk安装程序

a8jjtwal  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(461)

如标题中所述,我正尝试使用以下命令在批处理文件中下载jdk安装程序:

wget --verbose --show-progress --referer="https://download.oracle.com" --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe"

我从批处理文件中得到以下错误:

--2021-01-05 15:12:30--  https://download.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving download.oracle.com (download.oracle.com)... 23.212.156.99
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe [following]
--2021-01-05 15:12:30--  https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving edelivery.oracle.com (edelivery.oracle.com)... 2a02:26f0:2b00:3b4::366, 2a02:26f0:2b00:390::366, 104.124.198.35
Connecting to edelivery.oracle.com (edelivery.oracle.com)|2a02:26f0:2b00:3b4::366|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856056_4a223d45cbb97da535473401552470f5 [following]
--2021-01-05 15:12:31--  https://download.oracle.com/otn-pub/java/jdk/15.0.1B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856056_4a223d45cbb97da535473401552470f5
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2021-01-05 15:12:32 ERROR 404: Not Found.

但是

当我在cli中直接使用此命令行(更改wget.exe文件所在的cd)时,它会正确下载安装程序,如下所示:

--2021-01-05 15:19:43--  https://download.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving download.oracle.com (download.oracle.com)... 23.212.156.99
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe [following]
--2021-01-05 15:19:43--  https://edelivery.oracle.com/otn-pub/java/jdk/15.0.1%2B9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe
Resolving edelivery.oracle.com (edelivery.oracle.com)... 2a02:26f0:2b00:390::366, 2a02:26f0:2b00:3b4::366, 104.126.235.187
Connecting to edelivery.oracle.com (edelivery.oracle.com)|2a02:26f0:2b00:390::366|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/jdk/15.0.1+9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856489_c1f5f2310bf675762561de7d78160532 [following]
--2021-01-05 15:19:44--  https://download.oracle.com/otn-pub/java/jdk/15.0.1+9/51f4f36ad4ef43e39d0dfdbaf6549e32/jdk-15.0.1_windows-x64_bin.exe?AuthParam=1609856489_c1f5f2310bf675762561de7d78160532
Connecting to download.oracle.com (download.oracle.com)|23.212.156.99|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 167452312 (160M) [application/octet-stream]
Saving to: 'jdk-15.0.1_windows-x64_bin.exe'

我真的需要用这个命令一个脚本。
如果有人知道批处理文件和cli之间可能出了什么问题,我将非常感谢您的帮助。

ryhaxcpt

ryhaxcpt1#

比较输出中的URL。
cli url包含百分号 %2B 作为url编码字母的一部分。但是批处理脚本输出缺少这个百分号,因此导致错误的url。
cli输出 15.0.1%2B9 批量输出 15.0.1B9 因为批处理使用百分号 % 要识别变量,你必须转义它,如果你想按字面意思使用它。
因此,请尝试在批处理脚本中使用两个百分号 %% . 这将导致一个(正确的)单一的 % 在您的url中。

相关问题