C# Webclient problem with looping download? -


This is the implementation of my webclient, it is believed that this download should be continuous, but for some reason, that is not even debug Help, I got 1 success for the first time, then the rest failed. Does anyone know why?

 for  (int i = 1; i & lt; = count; i ++) {(webclient wc = new webclient ()) {wc.Headers ["Accept-Encoding"] = "Jizip"; Wc.Headers ["User-agent"] = "Mozilla / 4.0 (compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" ; Byte [] arr = wc.DownloadData (url); If (arr.Length & gt; 0) console. WrightLine (i.ToString () + ": SUCCESS"); Else console.light line (i.ToString () + ": failed"); }}  

When I messed up with this code, then it works That's right! I do not know what to say now ...

 using  (webclient client = new webclient ()) // // manipulate header (optional) customer. Header. Add ("User-agent", "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); // Execute and read the response as a string (StreamReader Reader = New Stream Reader (client.OpenRead (url)) {string s = reader.ReadToEnd (); //Console.WriteLine(s); Console.light line ("vote" + i.ToString () + ": success"); I ++; }} // *** Request HttpWebRequest loHttp = (HttpWebRequest) Install WebRequest.Create (url); // *** Set properties loHttp.Timeout = 10000; // 10 seconds loHttp.UserAgent = "Mozilla / 4.0 (compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; LoHttp.Headers ["Approved-encoding"] = "jizip"; // *** Retrieve Request Information Header HTTP Webbows Lowbesports = (HTTP Webbabs) LoHTP. Gate Response (); Encoding enc = encoding Gate encoding (1252); // Windows Default Code Page Stream Reader LowSponsStream = New Stream Reader (GaterespanSstream (), ANP); String lcHtml = loResponseStream.ReadToEnd (); LoWebResponse.Close (); LoResponseStream.Close (); If (lcHtml.Length & gt; 0) {Console.WriteLine ("vote" + i.ToString () + ": SUCCESS"); I ++; } And console.light line ("vote" + i.ToString () + ": failed"); }  

has been marked as a community wiki, so that anyone knows why, please edit ...: (


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -