本文整理汇总了C#中System.Net.Http.HttpClient.SetBasicAuthCredentials方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.SetBasicAuthCredentials方法的具体用法?C# HttpClient.SetBasicAuthCredentials怎么用?C# HttpClient.SetBasicAuthCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.SetBasicAuthCredentials方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIssues
private static async Task<IList<JToken>> GetIssues(string user, string password, Dictionary<string, string> parameters = null)
{
var httpClient = new HttpClient();
httpClient.SetBasicAuthCredentials(user, password);
var issues = new List<JToken>();
string resource = AddParameters("https://api.github.com/repos/signalr/signalr/issues", parameters);
string lastResource = null;
while (true)
{
Console.WriteLine("GET " + resource);
var response = await httpClient.GetAsync(resource);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response);
break;
}
else
{
var rateLimitRemainingValue = response.Headers.GetValues("X-RateLimit-Remaining").First();
int rateLimitRemaining;
if (Int32.TryParse(rateLimitRemainingValue, out rateLimitRemaining) && rateLimitRemaining < 10)
{
Console.WriteLine(rateLimitRemainingValue + " requests remaining");
}
var pageIssues = JArray.Parse(await response.Content.ReadAsStringAsync());
issues.AddRange(pageIssues);
if (resource.Equals(lastResource, StringComparison.OrdinalIgnoreCase))
{
break;
}
var resourceLinks = response.GetResourceLinks();
resource = resourceLinks[0];
if (String.IsNullOrEmpty(lastResource))
{
lastResource = resourceLinks[1];
}
}
}
return issues;
}