zoukankan      html  css  js  c++  java
  • c# 使用httpclient

    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/%E3%82%AA%E3%82%B9%E3%82%B9%E3%83%A1%E3%81%AE%E3%81%8A%E3%81%BE%E3%81%A8%E3%82%81%E3%83%AD%E3%83%BC%E3%83%B3.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);
                }
            }
        }
    }
    

      

  • 相关阅读:
    压测mysql连接数
    OpenStack SR-IOV
    Scheduler 租户虚机到不同host
    Neutron 集成 DPDK
    Centos 7 密码重置
    win10优化
    Aria
    tomcat lb cluster
    Tomcat.md
    varnish.md
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8058823.html
Copyright © 2011-2022 走看看