[英]Dropbox Request URL path to file C#
I have OneDrive & Google Drive successfully processing chunked download however Dropbox is giving me grief because I cannot get the correct http request path to the file. 我有OneDrive和Google Drive成功处理了分块下载,但是Dropbox让我感到悲伤,因为我无法获取文件的正确http请求路径。
I am not an expert in rest url's & endpoints, maybe someone can point me in the right direction for the acceptable dropbox request format for the latest UWP SDK. 我不是休息网址和终结点方面的专家,也许有人可以为我指出最新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);
}
I have read docs on Dropbox and it is not clear on the formatting for me, also I could not find a clear example anywhere. 我已经阅读了Dropbox上的文档,但格式尚不清楚,也找不到任何清晰的示例。
Thanks again! 再次感谢!
According to your code, the problem here is in your authorization header. 根据您的代码,这里的问题出在您的授权标头中。 For Dropbox API, the correct authorization header should like following: 对于Dropbox API,正确的授权标头应如下所示:
Authorization: Bearer <access token>
So we should change httpRequest.Headers.Authorization
to 所以我们应该将httpRequest.Headers.Authorization
更改为
httpRequest.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
Then your code should be albe to work. 然后您的代码应该可以正常工作。 Using "file.mp3" under "temp" folder for example. 例如,使用“ temp”文件夹下的“ file.mp3”。
The code may like: 该代码可能喜欢:
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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.