C# http proxy

8-30 1,228 views

HttpClient 设置代理

HttpClientHandler handler = new HttpClientHandler()
{
    Proxy = new WebProxy("45.63.58.40:8888"),
    UseProxy = true
};

HttpClient httpClient = new HttpClient(handler);

WebRequest 设置代理

WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Method = "GET";
myWebRequest.Proxy = new WebProxy("45.63.58.40:8888");

完整示例

public static void proxy_HttpClient()
{
    HttpClientHandler handler = new HttpClientHandler()
    {
        Proxy = new WebProxy("http://127.0.0.1:1080"),
        UseProxy = true,
    };

    HttpClient httpClient = new HttpClient(handler);

    String url = "http://typhoon.fly3w.com";
    HttpResponseMessage response = httpClient.GetAsync(new Uri(url)).Result;
    String result = response.Content.ReadAsStringAsync().Result;
    Console.WriteLine(result);
    Console.ReadLine();
}
public static void proxy_WebRequest()
{
    // Create a new request to the mentioned URL.               
    WebRequest myWebRequest = WebRequest.Create("https://typhoon.fly3w.com/");
    myWebRequest.Method = "DELETE";

    //WebProxy myProxy = new WebProxy();
    // Obtain the Proxy Prperty of the  Default browser.  
    //myProxy = (WebProxy)myWebRequest.Proxy;
    myWebRequest.Proxy = new WebProxy("112.74.26.117:80");

    //WebResponse myWebResponse = myWebRequest.GetResponse();
    WebResponse myWebResponse = myWebRequest.GetResponse();

    // Print the  HTML contents of the page to the console.
    Stream streamResponse = myWebResponse.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    Char[] readBuff = new Char[256];
    int count = streamRead.Read(readBuff, 0, 256);
    Console.WriteLine("\nThe contents of the Html pages are :");
    while (count > 0)
    {
        String outputData = new String(readBuff, 0, count);
        Console.Write(outputData);
        count = streamRead.Read(readBuff, 0, 256);
    }

    // Close the Stream object.
    streamResponse.Close();
    streamRead.Close();

    // Release the HttpWebResponse Resource.
    myWebResponse.Close();
    Console.WriteLine("\nPress any key to continue.........");
    Console.Read();
}

typescript 源码分析

https://www.cnblogs.com/xuld/p/12180913.html

阅读全文

flutter_gen config

const configDefaultYamlContent = ''' name: UNKNOWN flutter_gen: Optional output: lib/gen/ Optional line_length: 80 Optional parse_metadata: false ...

阅读全文

redis 函数的含义

您提供的函数列表是一个 Redis 客户端 API 的部分实现,通常用于与 Redis 数据库进行交互。以下是这些函数的简要解释,按类别进行分类以帮助理解其功能和用...

阅读全文

欢迎留言