Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. In C# how can i get list new URLs that is redirected from website?
  2. this.converts = new Thread(new ThreadStart(this.convert));
  3. this.converts.Start();
  4.  
  5. private void convert()
  6.         {   //I have to add this or it gives //
  7.  
  8.             Control.CheckForIllegalCrossThreadCalls = false;
  9.  
  10.             // Cross-thread operation not valid error//
  11.  
  12.  
  13.             string[] lines = this.textBox1.Lines;
  14.             for (int i = 0; i < lines.Length; i++)
  15.             {
  16.  
  17.                 if ((lines[i] != "") && lines[i].Contains("http://"))
  18.                 {
  19.                     string str = this.Get_Redirected_link(user, pass, lines[i]);
  20.                     this.textBox2.Text = this.textBox2.Text + str + "rn";
  21.                 }
  22.             }
  23. }
  24.  
  25. private string Get_Redirected_link(string username, string password, string url)
  26.         {
  27.             WebRequest request = WebRequest.Create(url);
  28.             string s = username + ":" + password;
  29.             CredentialCache cache = new CredentialCache();
  30.             cache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
  31.             request.Credentials = cache;
  32.             request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(s)));
  33.             try
  34.             {
  35.                 return request.GetResponse().ResponseUri.AbsoluteUri;
  36.             }
  37.             catch
  38.             {
  39.                 return "error";
  40.             }
  41.         }