MainViewModel:
public async Task<string> Httpclient(string link,string oauthToken)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", oauthToken);
HttpResponseMessage response = await client.PostAsync(link,new StringContent(""));
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return await response.Content.ReadAsStringAsync();
}
Get_account_ViewModel:
public class Get_Current_Account_ViewModel
{
MainViewModel mainViewModel = new MainViewModel();
public async Task<Model.Get_Current_Account.RootObject> get_current_account(string _accessToken)
{
var query = await mainViewModel.Httpclient("https://api.dropboxapi.com/2/users/get_current_account?access_token=_accessToken",_accessToken);
if (query != null)
{
var get_data = JsonConvert.DeserializeObject<Model.Get_Current_Account.RootObject>(query);
return get_data;
}
else
return null;
}
我试过两种方式:
调用API函数时出错&#34; users / get_current_account&#34;:意外的URL参数:&#34; access_token&#34;在Dropbox API上
var query = await mainViewModel.Httpclient(&#34; https://api.dropboxapi.com/2/users/get_current_account?access_token=_accessToken&#34;,_ accessToken);
请大家解决这个问题。我无法解决它。感谢。
答案 0 :(得分:0)
你是正确的摆脱access_token
参数,因为,正如错误所说,这不是一个有效的参数。
下一个错误表示您发送了错误的Content-Type
标头,因此请尝试发送正确的标头。 E.g。
HttpResponseMessage response = await client.PostAsync(
link, new StringContent("", System.Text.Encoding.UTF8, "application/json"));
(此代码未经测试,只需阅读the docs on StringContent
。)