
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.42 KB | hits: 20 | expires: Never
In C# how can i get list new URLs that is redirected from website?
this.converts = new Thread(new ThreadStart(this.convert));
this.converts.Start();
private void convert()
{ //I have to add this or it gives //
Control.CheckForIllegalCrossThreadCalls = false;
// Cross-thread operation not valid error//
string[] lines = this.textBox1.Lines;
for (int i = 0; i < lines.Length; i++)
{
if ((lines[i] != "") && lines[i].Contains("http://"))
{
string str = this.Get_Redirected_link(user, pass, lines[i]);
this.textBox2.Text = this.textBox2.Text + str + "rn";
}
}
}
private string Get_Redirected_link(string username, string password, string url)
{
WebRequest request = WebRequest.Create(url);
string s = username + ":" + password;
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
request.Credentials = cache;
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(s)));
try
{
return request.GetResponse().ResponseUri.AbsoluteUri;
}
catch
{
return "error";
}
}