c#将代理从ip:port拆分为ip port

时间:2017-09-21 13:10:51

标签: c#

我正在制作一个从txt文件中获取代理的代码。 但这些代理是代理:ip格式。 现在我希望它用作:

WebProxy myproxy = new WebProxy("202.141.226.154", 8080);

但是我如何在那里获得我的代理服务呢?工作

获取代理:

    string proxy(string filee)
    {
        int counter = 0;
        string line;
        Console.WriteLine("Found these proxies:");

        // Read the file and display it line by line.
        System.IO.StreamReader file =
           new System.IO.StreamReader(filee);
        while ((line = file.ReadLine()) != null)
        {
            Console.WriteLine(line);
            counter++;
        }
        Console.WriteLine("Total proxies:");
        Console.WriteLine(counter);
        file.Close();

        return "lol";
    }

使用代理登录:

public static void MainLogin(string user, string pass)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.roblox.com/NewLogin");
    string postData = String.Format("username={0}&password={1}&submitLogin=Log+In&ReturnUrl=", user, pass);
    byte[] data = Encoding.UTF8.GetBytes(postData);
    WebProxy myproxy = new WebProxy("202.141.226.154", 8080);
    myproxy.BypassProxyOnLocal = false;
    request.Proxy = myproxy;
    request.Method = "POST";
    request.AllowAutoRedirect = false;
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
        stream.Write(data, 0, data.Length);
    }
    reqCookie = RetrieveCookie(request);
}

那么,我怎么能让他们一起工作呢? 谢谢!

0 个答案:

没有答案