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

      

  • 相关阅读:
    Java搭建邮件服务器并发送Excel附件
    Java发送Http带HEADER参数
    MySql 技术内幕 (查询处理和子查询)
    《MySQL技术内幕:SQL编程》笔记
    MySql 技术内幕 (数据类型)
    替换Jar包里文件
    [Python数据分析]新股破板买入,赚钱几率如何?
    一些资料
    sqlval
    IBM CLI 和 ODBC
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8058823.html
Copyright © 2020-2023  润新知