OneDrive 文件下载 returns 95 字节内容

OneDrive file download returns 95 byte content

不确定具体从什么时候开始,但一些文件是通过 Graph API returns 95 字节内容从 OneDrive 下载的。而这一切就像下面。

{"error":{"code":"serviceNotAvailable","message":"Service unavailable","retryAfterSeconds":30}}

更准确地说,由以下 API 编辑的文件位置 return 的普通文件下载有问题。 https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get_content?view=odsp-graph-online

似乎服务器 return 将错误作为内容发送,而不是 returning HTTP 错误。 这与 'data-integrity' 有关,所以我认为您应该始终 return HTTP 错误。

事实证明,当发生超时时,C# HttpClient 在 AggregateException 中抛出 TaskCanceledException。

所以这不是 API 本身的问题,而是在处理 HttpClient 时需要格外小心。

需要修改 HttpClient 以抛出 HttpRequestException 或一些其他与 HTTP 相关的异常,而不是抛出 TaskCanceledException。