我正在尝试在我的代码中设置基本身份验证标头
using (var client = new HttpClient())
{
string username = "6B562D6XXXXAC1A58E5E474B2107FFDAA66EBE94";
string password = "FF8AFB9XXXX331CD0DF0A0C38D6ACD8502224764";
var uri = "https://xxxxxxx/token";
string svcCredentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", svcCredentials);
}
这将引发以下异常
我尝试了一些没有运气的变化
任何帮助解决的问题,将不胜感激
System.FormatException:'值'承载令牌System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox
1 [System.String,System.Runtime.CompilerServices.IAsyncStateMachine]的格式无效。'
尝试使用此功能TryAddWithoutValidation
:
类似:
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", svcCredentials);