"Header is missing" 尝试对API进行身份验证时出现错误。
"Header is missing" 尝试对API进行身份验证时出现错误。
我正在尝试在我的网站中连接并进行身份验证的API。API文档示例使用的是我对其了解甚少的CURL命令。
CURL命令如下:
curl -X POST \ --user ${client_id}:${client_secret} \ http://dashboard.myAPI.ir/oauth/token? grant_type=password&password=${your_login_password}&username=${your_login_user_name}'
以下是我试图将其转换为C#的代码:
var Username = "myuseranme"; var Password = "mypassword"; var SecretId = "mysecretid"; var ClinetID = "myclientid"; var httpClient = new HttpClient(); var authToken = Encoding.ASCII.GetBytes($"{ClinetID}:{SecretId}"); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken)); var response = await httpClient.GetAsync($"http://dashboard.packpay.ir/oauth/token?grant_type=password&pasword={Password}&username={Username}"); var content = await response.Content.ReadAsStringAsync();
运行代码后,content
的值是:
"{\"error\":\"unauthorized\",\"error_description\":\"Header is
missing\"}"
出了什么问题?