ITPub博客

首页 > 应用开发 > > 怎么用HttpClient获取网页内容?

怎么用HttpClient获取网页内容?

作者:emanda 时间:2019-08-29 10:44:53 0 删除 编辑

在获取https://s3.eu-central-1.amazonaws.com/ogatef/show.htm的内容时,代码如下:

try
        {
            var htmlSource = await httpClient.GetStringAsync(url);
            return htmlSource;
        }
        catch (HttpRequestException e)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"{nameof(HttpRequestException)}: {e.Message}");
            return null;
        }

可得到的htmlSource不是 网页string,而是“Id = 1, Status = Faulted, Method = "{null}", Result = "{Not yet computed}”,

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1741/viewspace-3119962/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    208
  • 访问量
    2574