我使用rest api
https://api.onedrive.com/v1.0/drive/items/ {fileID} /内容
下载OneDrive文件
当我尝试从OneDrive响应下载多个文件时返回错误:
The remote server returned an error: (429) Too Many Requests.
我尝试使用Retry-After响应标头在发送另一个请求之前等待,但是没有用。
是否有解决方案或解决此问题的方法?
我在c#中的示例代码:
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.onedrive.com/v1.0/drive/items/{fileID}/content");
request.Method = "GET";
request.Headers.Add("Authorization", "Bearer {accessToken}");
WebResponse response = request.GetResponse();
Stream fileStream = response.GetResponseStream();
}
catch (WebException ex)
{
HttpWebResponse res = (HttpWebResponse)ex.Response;
int retryAfter = 0;
if (!string.IsNullOrEmpty(res.Headers["Retry-After"]))
{
retryAfter = int.Parse(res.Headers["Retry-After"]);
}
Thread.Sleep(retryAfter);
//re-call same request function
}