![]() ![]() As a result, he became an English teacher and started his first company: The Hangzhou Haibo Translation Agency. Despite his developed English skills, Jack was a poor math student and failed the GaoKao (China’s college entrance exam) twice. Jack took this opportunity to practice his English by offering tours of the city. In 1978, Deng Xiaoping launched China’s Open Door Policy, which when coupled with President Nixon’s visit to Ma’s hometown a few years prior, led to a tourism flourishing. However, by his early teens, there were signs of China moving toward a new direction. If ((int)webResponse.StatusCode >= 300 & (int)webResponse.Alibaba founder Jack Ma was born in Hangzhou, China in 1964, a time when private enterprises were forbidden from operating. ![]() Using (webResponse = (HttpWebResponse)webRequest.GetResponse()) WebRequest.Timeout = 10000 // timeout 10s WebRequest.AllowAutoRedirect = false // IMPORTANT HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls This is a recursive function call here: public static string GrtUrl(string url, int counter) Good luck with the last one.Īfter reviewing everyone's suggestions I kind of figured this out for at least my case which basically did 3 loops once to https and second one to actual ending location. If you absolutely have to detect all redirects, then you would have to parse the HTML for META tags, look for Refresh: headers in the response, and evaluate Javascript. Most web crawlers, including the Googlebot, ignore these redirection methods, and so should you. Although these methods work in most browsers, they are definitely not guaranteed to work, and occasionally result in strange behavior (aka. These include meta refresh, the Refresh: header, and JavaScript. This is the way the gods intended HTTP redirects to work, and is also known as "the one true way." This method will work on all browsers and crawlers.Īnd then there are the devil's ways. The first way is to use a 3xx HTTP status code, and the Location: header. There's more than one way to redirect a browser to another URL. UPDATE: More clarification regarding redirects: So there's no easy way to detect the redirect.įor proper (HTTP Status Code and Location:) redirects, you might want to remove req.AllowAutoRedirect = false Īnd get the final URL using myResp.ResponseUri ![]() The URL you mentioned uses a JavaScript redirect, which will only redirect a browser. Doesn't have a URL Schema, meaning it's a relative or absolute URL Resp = (HttpWebResponse)req.GetResponse() Req = (HttpWebRequest) HttpWebRequest.Create(url) Int maxRedirCount = 8 // prevent infinite loops public static string GetFinalRedirect(string url) Notice that the previous solution didn't deal with Absolute & Relative URLs, since the LOCATION header could return something like "/newhome" you need to combine with the URL that served that response to identify the full URL destination. It doesn't account for JavaScript-based redirects or META redirects. This function will return the final destination of a link - even if there are multiple redirects. If I open the link in Internet Explorer then it will redirect to another URL and open the PDF file.Ĭan someone help me understand why it is not working properly for the example URL?īy the way, I checked with Hotmail's URL ( ) and it correctly returns the redirected URL. I am surprised why it is not considering it a redirection. When I execute the code above it gives me HttpStatusCodeOk. MessageBox.Show("redirected to:" + myResp.GetResponseHeader("Location")) If (myResp.StatusCode = HttpStatusCode.Redirect) HttpWebResponse myResp = (HttpWebResponse)req.GetResponse() I tried to use following code: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Uris) Is there some way through which I can pass my original URL string and get the redirected URL back? The problem is that some URLs get redirected to other URLs. I have to open those URLs and verify some links on those pages. I have a table in my database which contains the URLs of some websites.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |