Created
May 5, 2012 15:59
-
-
Save alexsandro-xpt/2603594 to your computer and use it in GitHub Desktop.
Comportamento estranho usando AsyncCTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> DownloadTaskAsync(string url) { | |
HeadOnly = true; | |
bool loop; | |
HttpWebResponse responseAsync; | |
do { | |
loop = false; | |
var webRequest = (HttpWebRequest) GetWebRequest(new Uri(url)); | |
webRequest.AllowAutoRedirect = false; | |
webRequest.KeepAlive = true; | |
responseAsync = (HttpWebResponse) await webRequest.GetResponseAsync(); /* Em um UNICO casos esta linha causa uma saída repentina neste método sem deixa exception qualquer outra coisa, retornando a linha de quem a chamou. */ | |
//var responseAsync = (HttpWebResponse)webRequest.GetResponse(); | |
//var responseAsync = (HttpWebResponse)GetWebResponse(webRequest); | |
int statusCode = (int) responseAsync.StatusCode; | |
Console.WriteLine(url + " - " + statusCode); | |
if ( /*(new[] { 301, 302 }).Contains(statusCode)*/statusCode == 301 || statusCode == 302) { | |
Console.Write(url); | |
url = new Uri(new Uri(url), responseAsync.Headers["Location"]).ToString(); | |
_url = url; | |
Console.WriteLine(" ---> " + url); | |
loop = true; | |
} | |
} while (loop); | |
if (responseAsync.StatusCode == HttpStatusCode.OK && responseAsync.ContentType.StartsWith(@"text/")) { | |
_progress.Id = CrawlHelper.IdPage(url); | |
HeadOnly = false; | |
return await this.DownloadStringTaskAsync(new Uri(url), _cts.Token, _progress); | |
} | |
return string.Empty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment