IDM 如何知道 google 驱动器文件大小?

How IDM knows google drive file sizes?

我正在使用 C# 集成下载管理器 Chrome。当我尝试从 google 驱动器下载时,响应不是 return Content-Length,这意味着 -1(未知)。但是 IDM 得到了正确的大小,我不明白如何。有知道的请帮忙!

此url中的文件:https://drive.google.com/uc?export=download&confirm=-wOm&id=1gC_fEKIlv9oaLQUAKH4GvRvAIqhDgAbz

回复headers:

X-GUploader-UploadID = AAANsUmzer2D7sJF5ROkgKYHrAfB994uetArTRtS2O1-2rcomguwXU2nVQ20nghtQbf4KHWoxVN8XQGlPSS_hj3hw1A
Access-Control-Allow-Origin = *
Access-Control-Allow-Credentials = false
Access-Control-Allow-Headers = Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, GData-Version, google-cloud-resource-prefix, x-goog-request-params, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, hotrod-board-name, hotrod-chrome-cpu-model, hotrod-chrome-processors, Want-Digest, x-chrome-connected, X-ClientDetails, X-Client-Version, X-Firebase-Locale, X-Goog-Firebase-Installations-Auth, X-Firebase-Client, X-Firebase-Client-Log-Type, X-GData-Client, X-GData-Key, X-GoogApps-Allowed-Domains, X-Goog-AdX-Buyer-Impersonation, X-Goog-Api-Client, X-Goog-AuthUser, x-goog-ext-124712974-jspb, x-goog-ext-251363160-jspb, x-goog-ext-259736195-jspb, X-Goog-PageId, X-Goog-Encode-Response-If-Executable, X-Goog-Correlation-Id, X-Goog-Request-Info, X-Goog-Request-Reason, X-Goog-Experiments, x-goog-iam-authority-selector, x-goog-iam-authorization-token, X-Goog-Spatula, X-Goog-Travel-Bgr, X-Goog-Travel-Settings, X-Goog-Upload-Command, X-Goog-Upload-Content-Disposition, X-Goog-Upload-Content-Length, X-Goog-Upload-Content-Type, X-Goog-Upload-File-Name, X-Goog-Upload-Header-Content-Encoding, X-Goog-Upload-Header-Content-Length, X-Goog-Upload-Header-Content-Type, X-Goog-Upload-Header-Transfer-Encoding, X-Goog-Upload-Offset, X-Goog-Upload-Protocol, x-goog-user-project, X-Goog-Visitor-Id, X-Goog-FieldMask, X-Google-Project-Override, X-Goog-Api-Key, X-HTTP-Method-Override, X-JavaScript-User-Agent, X-Pan-Versionid, X-Proxied-User-IP, X-Origin, X-Referer, X-Requested-With, X-Stadia-Client-Context, X-Upload-Content-Length, X-Upload-Content-Type, X-Use-HTTP-Status-Code-Override, X-Ios-Bundle-Identifier, X-Android-Package, X-Ariane-Xsrf-Token, X-YouTube-VVT, X-YouTube-Page-CL, X-YouTube-Page-Timestamp, X-Compass-Routing-Destination, X-Goog-Meeting-Botguardid, X-Goog-Meeting-ClientInfo, X-Goog-Meeting-ClientVersion, X-Goog-Meeting-Debugid, X-Goog-Meeting-RtcClient, X-Goog-Meeting-Token, X-Goog-Meeting-StartSource, X-Client-Data, X-Sfdc-Authorization, MIME-Version, Content-Transfer-Encoding, X-Earth-Engine-App-ID-Token, X-Earth-Engine-Computation-Profile, X-Earth-Engine-Computation-Profiling, X-Play-Console-Experiments-Override, X-Play-Console-Session-Id, x-alkali-account-key, x-alkali-application-key, x-alkali-auth-apps-namespace, x-alkali-auth-entities-namespace, x-alkali-auth-entity, x-alkali-client-locale, EES-S7E-MODE, cast-device-capabilities
Access-Control-Allow-Methods = GET,OPTIONS
Content-Disposition = attachment;filename="[saglamindir.net]VirtualBox-6.1.2.rar";filename*=UTF-8''%5Bsaglamindir.net%5DVirtualBox-6.1.2.rar
X-Goog-Hash = crc32c=C7PP8g==
Transfer-Encoding = chunked
Alt-Svc = h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Connection = close
Cache-Control = private, max-age=0
Content-Type = application/rar
Date = Sat, 08 Aug 2020 21:16:02 GMT
Expires = Sat, 08 Aug 2020 21:16:02 GMT
Server = UploadServer

您还没有发布您的代码来审查您的问题。但是,您应该在 Google Drive requests 中考虑两件事。首先,您应该使用 Google API 来处理请求。这意味着,您必须通过 OAuth2 协议进行经过身份验证的请求。

如果您使用他们的 NuGets,那么您可以简单地使用 DriveService 来获取文件大小。

var file = service.Files.Get(fileId).Execute();
var size = file.FileSize;

如果您使用 HttpWebRequestHttpClient(使用适当的 headers 和经过身份验证的请求),您的响应将被 GZip 编码(检查 Transfer-Encoding) 因此,您的响应的 body 长度将始终小于实际字节长度。 您需要对其进行解码以获得正确的长度。 (检查 HttpWebRequest.AutomaticDecompression OR HttpClientHandler.AutomaticDecompression

你可以这样解压:

HttpWebRequest

var request = (HttpWebRequest) WebRequest.Create(fileUrl);
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
// your code

HttpClient

var handler = new HttpClientHandler()
{
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};        
var client = new HttpClient(handler);
// your code