Dropbox 请求 URL 文件 C# 的路径
Dropbox Request URL path to file C#
我有 OneDrive 和 Google 驱动器成功处理了分块下载,但是 Dropbox 让我很伤心,因为我无法获得文件的正确 http 请求路径。
我不是 rest url 和端点方面的专家,也许有人可以为我指出最新 UWP SDK 可接受的保管箱请求格式的正确方向。
using (var httpRequest = new HttpRequestMessage())
{
string url = "https://content.dropboxapi.com/1/files/auto" + uri;
string accessKey = ApplicationData.Current.LocalSettings.Values[CommonData.dropboxAccessToken_Key].ToString();
httpRequest.Method = HttpMethod.Get;
httpRequest.RequestUri = new Uri(url);
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", accessKey);
}
我已经阅读了 Dropbox 上的文档,但我不清楚格式,而且我在任何地方都找不到明确的示例。
再次感谢!
根据你的代码,这里的问题出在你的授权上header。对于 Dropbox API,正确的授权 header 应该如下所示:
Authorization: Bearer <access token>
所以我们应该把httpRequest.Headers.Authorization
改成
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
那么您的代码应该可以正常工作了。例如,使用 "temp" 文件夹下的 "file.mp3"。
代码可能喜欢:
var uri = "/temp/file.mp3";
using (var httpClient = new HttpClient())
{
using (var httpRequest = new HttpRequestMessage())
{
string url = "https://content.dropboxapi.com/1/files/auto" + Uri.EscapeDataString(uri);
httpRequest.Method = HttpMethod.Get;
httpRequest.RequestUri = new Uri(url);
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
var response = await httpClient.SendAsync(httpRequest);
if (response.IsSuccessStatusCode)
{
//TODO
}
}
}
我有 OneDrive 和 Google 驱动器成功处理了分块下载,但是 Dropbox 让我很伤心,因为我无法获得文件的正确 http 请求路径。
我不是 rest url 和端点方面的专家,也许有人可以为我指出最新 UWP SDK 可接受的保管箱请求格式的正确方向。
using (var httpRequest = new HttpRequestMessage())
{
string url = "https://content.dropboxapi.com/1/files/auto" + uri;
string accessKey = ApplicationData.Current.LocalSettings.Values[CommonData.dropboxAccessToken_Key].ToString();
httpRequest.Method = HttpMethod.Get;
httpRequest.RequestUri = new Uri(url);
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", accessKey);
}
我已经阅读了 Dropbox 上的文档,但我不清楚格式,而且我在任何地方都找不到明确的示例。
再次感谢!
根据你的代码,这里的问题出在你的授权上header。对于 Dropbox API,正确的授权 header 应该如下所示:
Authorization: Bearer <access token>
所以我们应该把httpRequest.Headers.Authorization
改成
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
那么您的代码应该可以正常工作了。例如,使用 "temp" 文件夹下的 "file.mp3"。
代码可能喜欢:
var uri = "/temp/file.mp3";
using (var httpClient = new HttpClient())
{
using (var httpRequest = new HttpRequestMessage())
{
string url = "https://content.dropboxapi.com/1/files/auto" + Uri.EscapeDataString(uri);
httpRequest.Method = HttpMethod.Get;
httpRequest.RequestUri = new Uri(url);
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
var response = await httpClient.SendAsync(httpRequest);
if (response.IsSuccessStatusCode)
{
//TODO
}
}
}