Click here to Skip to main content
15,888,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to do a multithreaded proxychecker, however GetResponse throwing errors. I'm stuck please help.

C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;


namespace ProxyChecker
{



    internal class Program
    {

        private static void Main(string[] args)
        {
            string path = "C:\\users\\zsolt\\desktop\\proxies.txt";
            //string path = args[0];
            List<string> proxies = File.ReadLines(path).ToList();

            Parallel.ForEach(proxies, proxy =>
            {


                WebProxy myproxy = new WebProxy(proxy);
                WebRequest myWebRequest = WebRequest.Create("http://www.google.com");
                myWebRequest.Timeout = 3000;
                myWebRequest.Proxy = myproxy;
                WebResponse myWebResponse = myWebRequest.GetResponse();
                myWebResponse.Close();

                try
                {
                    using (WebResponse response = myWebRequest.GetResponse())
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse) response;
                        Console.WriteLine(proxy, httpResponse.StatusCode);
                    }
                }
                catch
                    (WebException e)
                {
                    using (WebResponse response = e.Response)
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse) response;
                        Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
                        using (Stream data = response.GetResponseStream())
                        {
                            string text = new StreamReader(data).ReadToEnd();
                            Console.WriteLine(proxy, text);
                        }
                    }
                }

                });

                Console.Read();
            }
        }
  }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900