尝试下载文件时OneDrive Rest API太多请求错误

时间:2018-07-04 06:47:12

标签: c# onedrive

我使用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
}

0 个答案:

没有答案