Open xianqiang1 opened 3 years ago
Any solution as same issue i am getting too
对我来说, 第一个版本服务端没有对文件下载进行鉴权限制,可以正常下载,第二个版本,服务端开始改造增加鉴权,对已经调用过一次的下载链接进行失效处理,我这边就会遇到下面这样的异常,
ava.net.SocketException: Connection failed with request[{Range=[bytes=4073926-8147851], User-Agent=[FileDownloader/1.7.7]}] response[{null=[HTTP/1.1 403 Forbidden], Access-Control-Allow-Methods=[GET], Access-Control-Allow-Origin=[*], Connection=[keep-alive], Content-Length=[238], Content-Type=[text/html], Date=[Mon, 29 Jan 2024 02:42:16 GMT], EagleId=[907b1f2217064961368347077e], Server=[Tengine], Timing-Allow-Origin=[*], Via=[cache14.cn1306[,0]], X-Android-Received-Millis=[1706496136376], X-Android-Response-Source=[NETWORK 403], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1706496136196]}] http-state[403] on task[-891346639-1], which is changed after verify connection, so please try again.
最终发现是因为 下载库默认开启断点续传。
Range 是一个请求首部,告知服务器返回文件的哪一部分。在一个 Range 首部中,可以一次性请求多个部分,服务器会以 multipart 文件的形式将其返回。如果服务器返回的是范围响应,需要使用 206 Partial Content 状态码。假如所请求的范围不合法,那么服务器会返回 416 Range Not Satisfiable 状态码,表示客户端错误。服务器允许忽略 Range 首部,从而返回整个文件,状态码用 200 。
所以我这边的情况是,服务端做修改适配客户端的断点续传,客户端不需要修改。
request headers: {Range=[bytes=0-0], User-Agent=[FileDownloader/1.7.6]} response headers: {null=[HTTP/1.1 403 Forbidden], Connection=[Close], Content-Length=[2727], Content-Security-Policy=[frame-ancestors], Content-Type=[text/html; charset="utf-8"], X-Android-Received-Millis=[1604387185556], X-Android-Response-Source=[NETWORK 403], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1604387185546], X-Content-Type-Options=[nosniff], X-Frame-Options=[SAMEORIGIN], X-XSS-Protection=[1; mode=block]}
Chrome can be downloaded, and the server does not impose any restrictions. With this download, there are some places where the download can't be reported. The log shows 403