How to extend urls in C #?

If I have a URL like http://popurls.com/go/msn.com/l4eba1e6a0ffbd9fc915948434423a7d5 , how can I programmatically expand it to the original URL? Obviously, I could use an API like expandurl.com , but that would limit me to 100 requests per hour.

+3
source share
2 answers

Request a URL and check the status code returned. If 301or 302, find the heading Locationthat will contain the "rich URL":

string url = "http://popurls.com/go/msn.com/l4eba1e6a0ffbd9fc915948434423a7d5";

var request = (HttpWebRequest) WebRequest.Create(url);            
request.AllowAutoRedirect = false;

var response = (HttpWebResponse) webRequest.GetResponse();

if ((int) response.StatusCode == 301 || (int) response.StatusCode == 302)
{
    url = response.Headers["Location"];
}

. , . . URL- obfuscators (bit.ly .), .

+7

.

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://popurls.com/go/msn.com/l4eba1e6a0ffbd9fc915948434423a7d5");
    req.AllowAutoRedirect = true;
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();
    ServicePoint sp = req.ServicePoint;
    Console.WriteLine("End address is " + sp.Address.ToString());
+1

Source: https://habr.com/ru/post/1739655/


All Articles