我正在.NET 3.1中的Blazor应用程序上工作,在该应用程序中我必须访问URL,要访问它,我必须执行基本身份验证。
我在班级索引Base.cs中有以下代码
public async void call()
{
try
{
string username = "urs", password = "pass";
string payload = "http://localhost/ReportServer";
HttpClient client = new HttpClient();
var byteArray = Encoding.ASCII.GetBytes($"{username}:{password}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
HttpResponseMessage response = await client.GetAsync(payload);
HttpContent content = response.Content;
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Success");
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Console.WriteLine("Auth error");
}
else
{
Console.WriteLine(response.StatusCode);
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
输入成功的“ if”后,如何在另一个浏览器选项卡中发送相同的URL并获得输入权限?