c# 使用httpclient

mac2022-06-30  20

using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("开始访问网络"); GetData(); Console.WriteLine("结束访问"); Console.ReadKey(); } static async void GetData() { HttpClientHandler hander = new HttpClientHandler(); hander.AllowAutoRedirect = false; HttpClient httpClient = new HttpClient(hander); HttpResponseMessage response = null; // string NavigateUrl = "http://おまとめローン審査基準.com/オススメのおまとめローン.php"; string NavigateUrl = "http://www.baidu.com"; Uri uri = new Uri(NavigateUrl); IdnMapping idn = new IdnMapping(); NavigateUrl = NavigateUrl.Replace(uri.Host, idn.GetAscii(uri.Host)); response = await httpClient.GetAsync(NavigateUrl); // string loction = httpClient.GetAsync(NavigateUrl).Result.Headers.Location.ToString(); if (response.IsSuccessStatusCode) { string responseBodyAsText = response.Content.ReadAsStringAsync().Result; Console.WriteLine(responseBodyAsText); } } } }

  

转载于:https://www.cnblogs.com/c-x-a/p/8058823.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)