Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在HTTP客户端中使用公共代理服务器_C#_Http_Proxy - Fatal编程技术网

C# 在HTTP客户端中使用公共代理服务器

C# 在HTTP客户端中使用公共代理服务器,c#,http,proxy,C#,Http,Proxy,我正在尝试使用公共代理服务器(http://www.unblockwebnow.info/)要向目标站点发送HTTP请求,请说:) 我的HTTP客户端具有以下体系结构: string url = "http://stackoverflow.com"; HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url); HttpWRequest.Method = "GET"; WebProxy myProxy = new W

我正在尝试使用公共代理服务器(http://www.unblockwebnow.info/)要向目标站点发送HTTP请求,请说:)

我的HTTP客户端具有以下体系结构:

string url = "http://stackoverflow.com";
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWRequest.Method = "GET";

WebProxy myProxy = new WebProxy();
myProxy.Address = new Uri("http://www.unblockwebnow.info/");
HttpWRequest.Proxy = myProxy;

HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), encoding);
var rawHTML = sr.ReadToEnd();
sr.Close();
执行rawHTML的代码后,我得到了“pageok-由puppet管理-hostingcms02 pageok”


如果我注释掉
HttpWRequest.Proxy=myProxy行,我获取站点内容。

这似乎有效,但不适用于您的代理(不知道unblockwebnow.info的端口号)。 在URI中的“:”之后添加了端口号


代理地址乱七八糟。看起来像一个垃圾网站。如果它不能与他的代理一起工作,那么这并不能回答他的问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://stackoverflow.com";
            HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWRequest.Method = "GET";

            WebProxy myProxy = new WebProxy();

            //United States proxy, from http://www.hidemyass.com/proxy-list/
            myProxy.Address = new Uri("http://72.64.146.136:8080");
            HttpWRequest.Proxy = myProxy;

            HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
            StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), true);
            var rawHTML = sr.ReadToEnd();
            sr.Close();

            Console.Out.WriteLine(rawHTML);
            Console.ReadKey();
        }
    }
}