首页 > 应用开发 > > 怎么用HttpClient获取网页内容?
在获取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/ ,如需转载,请注明出处,否则将追究法律责任。