Long URLs from short ones using C#












3















I've been using the LongURL.org API for expanding short URLs. The great thing about this service is that it returns a long URL, the title of the actual page and meta-info.



The real problem I have is that it seems to take an inordinate amount of time to fetch the data. I'm considering shifting the request to JavaScript so that the URL is fetched via an AJAX update panel, in order that the page loads quickly, and the URL data is updated while the user looks at the content (some search results).



Does anyone know how else I could gather the info described above, in a better time-frame? I'm using C# ASP.NET but would consider solutions in other languages. Any guidance in this area is much appreciated.










share|improve this question























  • Does anyone know why these look-up services might be so slow??

    – Alex
    Jul 4 '10 at 17:51






  • 1





    probably because they are overworked and underfunded.

    – matt-dot-net
    Jul 4 '10 at 18:35
















3















I've been using the LongURL.org API for expanding short URLs. The great thing about this service is that it returns a long URL, the title of the actual page and meta-info.



The real problem I have is that it seems to take an inordinate amount of time to fetch the data. I'm considering shifting the request to JavaScript so that the URL is fetched via an AJAX update panel, in order that the page loads quickly, and the URL data is updated while the user looks at the content (some search results).



Does anyone know how else I could gather the info described above, in a better time-frame? I'm using C# ASP.NET but would consider solutions in other languages. Any guidance in this area is much appreciated.










share|improve this question























  • Does anyone know why these look-up services might be so slow??

    – Alex
    Jul 4 '10 at 17:51






  • 1





    probably because they are overworked and underfunded.

    – matt-dot-net
    Jul 4 '10 at 18:35














3












3








3


2






I've been using the LongURL.org API for expanding short URLs. The great thing about this service is that it returns a long URL, the title of the actual page and meta-info.



The real problem I have is that it seems to take an inordinate amount of time to fetch the data. I'm considering shifting the request to JavaScript so that the URL is fetched via an AJAX update panel, in order that the page loads quickly, and the URL data is updated while the user looks at the content (some search results).



Does anyone know how else I could gather the info described above, in a better time-frame? I'm using C# ASP.NET but would consider solutions in other languages. Any guidance in this area is much appreciated.










share|improve this question














I've been using the LongURL.org API for expanding short URLs. The great thing about this service is that it returns a long URL, the title of the actual page and meta-info.



The real problem I have is that it seems to take an inordinate amount of time to fetch the data. I'm considering shifting the request to JavaScript so that the URL is fetched via an AJAX update panel, in order that the page loads quickly, and the URL data is updated while the user looks at the content (some search results).



Does anyone know how else I could gather the info described above, in a better time-frame? I'm using C# ASP.NET but would consider solutions in other languages. Any guidance in this area is much appreciated.







c# asp.net api url expander






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 4 '10 at 15:00









AlexAlex

2,83243753




2,83243753













  • Does anyone know why these look-up services might be so slow??

    – Alex
    Jul 4 '10 at 17:51






  • 1





    probably because they are overworked and underfunded.

    – matt-dot-net
    Jul 4 '10 at 18:35



















  • Does anyone know why these look-up services might be so slow??

    – Alex
    Jul 4 '10 at 17:51






  • 1





    probably because they are overworked and underfunded.

    – matt-dot-net
    Jul 4 '10 at 18:35

















Does anyone know why these look-up services might be so slow??

– Alex
Jul 4 '10 at 17:51





Does anyone know why these look-up services might be so slow??

– Alex
Jul 4 '10 at 17:51




1




1





probably because they are overworked and underfunded.

– matt-dot-net
Jul 4 '10 at 18:35





probably because they are overworked and underfunded.

– matt-dot-net
Jul 4 '10 at 18:35












1 Answer
1






active

oldest

votes


















5














Here's one I've used in a project before ...



private string UrlLengthen(string url)
{
string newurl = url;

bool redirecting = true;

while (redirecting)
{

try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newurl);
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((int)response.StatusCode == 301 || (int)response.StatusCode == 302)
{
string uriString = response.Headers["Location"];
Log.Debug("Redirecting " + newurl + " to " + uriString + " because " + response.StatusCode);
newurl = uriString;
// and keep going
}
else
{
Log.Debug("Not redirecting " + url + " because " + response.StatusCode);
redirecting = false;
}
}
catch (Exception ex)
{
ex.Data.Add("url", newurl);
Exceptions.ExceptionRecord.ReportWarning(ex); // change this to your own
redirecting = false;
}
}
return newurl;
}





share|improve this answer
























  • That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

    – Alex
    Jul 5 '10 at 12:47











  • I mean address...

    – Alex
    Jul 5 '10 at 21:18






  • 1





    Use the Html Agility Pack for that step

    – Ian Mercer
    Jul 5 '10 at 22:05











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3175062%2flong-urls-from-short-ones-using-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Here's one I've used in a project before ...



private string UrlLengthen(string url)
{
string newurl = url;

bool redirecting = true;

while (redirecting)
{

try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newurl);
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((int)response.StatusCode == 301 || (int)response.StatusCode == 302)
{
string uriString = response.Headers["Location"];
Log.Debug("Redirecting " + newurl + " to " + uriString + " because " + response.StatusCode);
newurl = uriString;
// and keep going
}
else
{
Log.Debug("Not redirecting " + url + " because " + response.StatusCode);
redirecting = false;
}
}
catch (Exception ex)
{
ex.Data.Add("url", newurl);
Exceptions.ExceptionRecord.ReportWarning(ex); // change this to your own
redirecting = false;
}
}
return newurl;
}





share|improve this answer
























  • That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

    – Alex
    Jul 5 '10 at 12:47











  • I mean address...

    – Alex
    Jul 5 '10 at 21:18






  • 1





    Use the Html Agility Pack for that step

    – Ian Mercer
    Jul 5 '10 at 22:05
















5














Here's one I've used in a project before ...



private string UrlLengthen(string url)
{
string newurl = url;

bool redirecting = true;

while (redirecting)
{

try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newurl);
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((int)response.StatusCode == 301 || (int)response.StatusCode == 302)
{
string uriString = response.Headers["Location"];
Log.Debug("Redirecting " + newurl + " to " + uriString + " because " + response.StatusCode);
newurl = uriString;
// and keep going
}
else
{
Log.Debug("Not redirecting " + url + " because " + response.StatusCode);
redirecting = false;
}
}
catch (Exception ex)
{
ex.Data.Add("url", newurl);
Exceptions.ExceptionRecord.ReportWarning(ex); // change this to your own
redirecting = false;
}
}
return newurl;
}





share|improve this answer
























  • That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

    – Alex
    Jul 5 '10 at 12:47











  • I mean address...

    – Alex
    Jul 5 '10 at 21:18






  • 1





    Use the Html Agility Pack for that step

    – Ian Mercer
    Jul 5 '10 at 22:05














5












5








5







Here's one I've used in a project before ...



private string UrlLengthen(string url)
{
string newurl = url;

bool redirecting = true;

while (redirecting)
{

try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newurl);
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((int)response.StatusCode == 301 || (int)response.StatusCode == 302)
{
string uriString = response.Headers["Location"];
Log.Debug("Redirecting " + newurl + " to " + uriString + " because " + response.StatusCode);
newurl = uriString;
// and keep going
}
else
{
Log.Debug("Not redirecting " + url + " because " + response.StatusCode);
redirecting = false;
}
}
catch (Exception ex)
{
ex.Data.Add("url", newurl);
Exceptions.ExceptionRecord.ReportWarning(ex); // change this to your own
redirecting = false;
}
}
return newurl;
}





share|improve this answer













Here's one I've used in a project before ...



private string UrlLengthen(string url)
{
string newurl = url;

bool redirecting = true;

while (redirecting)
{

try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newurl);
request.AllowAutoRedirect = false;
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if ((int)response.StatusCode == 301 || (int)response.StatusCode == 302)
{
string uriString = response.Headers["Location"];
Log.Debug("Redirecting " + newurl + " to " + uriString + " because " + response.StatusCode);
newurl = uriString;
// and keep going
}
else
{
Log.Debug("Not redirecting " + url + " because " + response.StatusCode);
redirecting = false;
}
}
catch (Exception ex)
{
ex.Data.Add("url", newurl);
Exceptions.ExceptionRecord.ReportWarning(ex); // change this to your own
redirecting = false;
}
}
return newurl;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 5 '10 at 1:33









Ian MercerIan Mercer

30.4k570104




30.4k570104













  • That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

    – Alex
    Jul 5 '10 at 12:47











  • I mean address...

    – Alex
    Jul 5 '10 at 21:18






  • 1





    Use the Html Agility Pack for that step

    – Ian Mercer
    Jul 5 '10 at 22:05



















  • That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

    – Alex
    Jul 5 '10 at 12:47











  • I mean address...

    – Alex
    Jul 5 '10 at 21:18






  • 1





    Use the Html Agility Pack for that step

    – Ian Mercer
    Jul 5 '10 at 22:05

















That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

– Alex
Jul 5 '10 at 12:47





That's really useful, cheers... I might do this, and then look into extracting HTML Doc titles from the given domain name

– Alex
Jul 5 '10 at 12:47













I mean address...

– Alex
Jul 5 '10 at 21:18





I mean address...

– Alex
Jul 5 '10 at 21:18




1




1





Use the Html Agility Pack for that step

– Ian Mercer
Jul 5 '10 at 22:05





Use the Html Agility Pack for that step

– Ian Mercer
Jul 5 '10 at 22:05




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3175062%2flong-urls-from-short-ones-using-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?