您的位置:首页 > 理论基础 > 计算机网络

HttpClient异步调用WEB服务

2015-08-07 15:29 309 查看
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);
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: