简体   繁体   English

使用C#HttpClient授权POST到Vimeo API

[英]Authorising POST to Vimeo API with C# HttpClient

I am trying to make a POST to the Vimeo API but I am getting 401 Authorization Required . 我正在尝试对Vimeo API进行POST,但是我401 Authorization Required

This is my code for the request (I am just sending the first request that the docs says should return me a ticket ID for uploading). 这是我的请求代码(我只是发送第一个请求,即文档说应该返回我要上传的票证ID)。

HttpClient client = new HttpClient();

client.BaseAddress = new Uri("https://api.vimeo.com");
var byteArray = Encoding.ASCII.GetBytes(accessToken);
client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

var form = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string, string>("type","POST")
            });
var response = await client.PostAsync("/me/videos", form);
response.EnsureSuccessStatusCode();

var result = await response.Content.ReadAsStringAsync();

I also tried adding access token like this: 我也尝试添加访问令牌,如下所示:

client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Basic", accessToken);

It always return 401. 它总是返回401。

What is proper way to add the access token? 添加访问令牌的正确方法是什么?

This is how header must be: 标头必须这样:

client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Bearer", accessToken);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM