(also, if anybody could tell me how to make it so that the code is actually readable, that would be appreciated.
It makes sense when I'm editing it but the final product is a bit messy)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
-
- static String DownloadPage(Uri url, string line)
- {
- WebProxy proxy = new WebProxy(line, true);
- WebRequest http = HttpWebRequest.Create(url);
- http.Timeout = 1000;
- HttpWebResponse response = (HttpWebResponse)http.GetResponse();
- StreamReader stream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII);
- String result = stream.ReadToEnd();
- response.Close();
- stream.Close();
- return result;
- }
- static void Main(string[] args)
- {
-
- StreamWriter sw = new StreamWriter("goodsites.txt", true);
- StreamReader sr = new StreamReader("fullsites.txt");
- string line = sr.ReadLine();
- while (line != null)
- {
-
- string u = (line);
- Uri url = new Uri(u);
- Console.WriteLine("Sites...");
- Console.WriteLine(line);
- Console.WriteLine("This is the response:");
- try
- {
- string result = "";
- result = DownloadPage(url, line);
- Console.WriteLine(result);
- if (result != null)
- {
- sw.WriteLine(line);
- }
- }
- catch (UriFormatException e)
- {
- Console.WriteLine("invalid URL");
- }
- catch (IOException e)
- {
- Console.WriteLine("invalid");
- }
- catch (WebException webExcp)
- {
-
- Console.WriteLine(webExcp.ToString());
-
- WebExceptionStatus status = webExcp.Status;
- if (status == WebExceptionStatus.ProtocolError)
- {
- Console.Write("The server returned protocol error ");
-
- HttpWebResponse httpResponse = (HttpWebResponse)webExcp.Response;
- Console.WriteLine((int)httpResponse.StatusCode + " - "
- + httpResponse.StatusCode);
- }
- }
- Console.WriteLine("");
- Console.WriteLine("");
- line = sr.ReadLine();
- }
- sr.Close();
- sw.Close();
- Console.WriteLine("All done!");
- Console.ReadKey();
- }
- }
- }