zoukankan      html  css  js  c++  java
  • HttpClient异步调用WEB服务

    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);
                }
    
            }
        }
    }
  • 相关阅读:
    HTML页引用CSS
    C#反射
    Marshal.SecureStringToBSTR
    SQL语句创建表和数据库
    抽象类和抽象方法
    3 Sum Closest
    Chapter 2: Binary Search & Sorted Array
    Spiral Matrix
    Pascal's Triangle
    Plus One
  • 原文地址:https://www.cnblogs.com/ZXdeveloper/p/4710923.html
Copyright © 2011-2022 走看看