我是一个编程新手....我在Visual Studio 2017中用下面的代码编写了一个ConsoleApp....
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace HttpClientStatus
{
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var result = await client.GetAsync("http://webcode.me");
Console.WriteLine(result.StatusCode);
}
}
}
Build运行成功,但执行exe文件后,屏幕上似乎没有任何东西显示出来。
控制台的输出应该是这样的。
$ dotnet run
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My html page</title>
</head>
<body>
<p>
Today is a beautiful day. We go swimming and fishing.
</p>
<p>
Hello there. How are you?
</p>
</body>
</html>
请帮助...
Regards...
把 Console.Read();
此后 Console.WriteLine(result.StatusCode);
如果你不这样做,代码将完全运行,但不会向你显示任何东西。