using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace HttpClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("开始");
            GetData();
            Console.WriteLine("结束");
            Console.ReadKey();
        }

        private static async void GetData()
        {
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = null;
            response = await httpClient.GetAsync("http://wcf.open.cnblogs.com/blog/sitehome/recent/10");
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Response Status Code:" + response.StatusCode + " " + response.ReasonPhrase);
                string responseBodyAsText = response.Content.ReadAsStringAsync().Result;
                Console.WriteLine(responseBodyAsText);
            }

        }
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-03-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案