本文整理汇总了C#中HttpClient.GetJsonAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.GetJsonAsync方法的具体用法?C# HttpClient.GetJsonAsync怎么用?C# HttpClient.GetJsonAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.GetJsonAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArticleAsync
public async Task<DataResultBase<Article>> GetArticleAsync(Feed feed)
{
if (feed == null)
{
throw new ArgumentNullException(nameof(feed));
}
string url = string.Format(ArticleTemplate, feed.Id);
using (HttpClient client = new HttpClient())
{
return await client.GetJsonAsync<DataResultBase<Article>>(new Uri(url));
}
}
示例2: GetFeedListAsync
public async Task<DataResultBase<ResultList<Feed>>> GetFeedListAsync(FeedCategory category, int page = 1)
{
if (Enum.IsDefined(typeof(FeedCategory), category) == false)
{
throw new ArgumentException($"{nameof(category)} is not defined.", nameof(category));
}
if (page <= 0)
{
throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
}
string url = string.Format(CategoryListTemplate, (int)category, page);
using (HttpClient client = new HttpClient())
{
return await client.GetJsonAsync<DataResultBase<ResultList<Feed>>>(new Uri(url));
}
}
示例3: GetCommentsAsync
public async Task<DataResultBase<ResultList<Comment>>> GetCommentsAsync(Feed feed, int page = 1)
{
if (feed == null)
{
throw new ArgumentNullException(nameof(feed));
}
if (page <= 0)
{
throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
}
string url = string.Format(GetCommentTemplate, feed.Id, page);
url = url + "?t=" + DateTime.Now.Ticks;
using (HttpClient client = new HttpClient())
{
return await client.GetJsonAsync<DataResultBase<ResultList<Comment>>>(new Uri(url));
}
}
示例4: GetSearchResultsAsync
public Task<DataResultBase<ResultList<Feed>>> GetSearchResultsAsync(string keyword, int page = 1)
{
if (keyword == null)
{
throw new ArgumentNullException(nameof(keyword));
}
if (keyword.Length <= 0)
{
throw new ArgumentException("query could not be empty.", nameof(keyword));
}
if (page <= 0)
{
throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero.");
}
string url = string.Format(SearchTemplate, page, keyword);
using (HttpClient client = new HttpClient())
{
return client.GetJsonAsync<DataResultBase<ResultList<Feed>>>(new Uri(url));
}
}