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);
                }
            }
        }
    }
    

      

  • 相关阅读:
    年入50万的众生相
    【史上最全面经】银行类
    Dubbo背景和简介
    剑指Offer66题的总结、目录
    如何写一份更好的简历
    Linux命令 file
    Linux命令 umask
    Linux perm
    Linux 命令 which whereis locate find
    Linux命令 diff cmp patch
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8058823.html
Copyright © 2011-2022 走看看