尝试向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的值是这样:

“ {\”错误\“:\”未经授权\“,\”错误说明\“:\”标题为 丢失\“}”

怎么了?

cywmm 回答:尝试向API进行身份验证时出现“标头丢失”错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2530400.html

大家都在问