更新时间:2022-06-26 21:49:33
下面是一个使用样本的HttpClient:
Here is a sample using HttpClient:
public static async Task<String> Login(string username, string password)
{
HttpClient Client = new HttpClient();
Client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(StringToAscii(string.Format("{0}:{1}", username, password))));
var response = await Client.GetAsync(new Uri(new Uri("http://yourdomain.com"), "/login"));
var status= await response.Content.ReadAsAsync<String>();
return status;
}
当然,你可以在互联网上找到的ToBase64String功能。这里最棘手的部分是Authorization头。
And of course you can find the ToBase64String function on the internet. The tricky part here is the Authorization header.