internal string GetWebContent(Uri uri) { string tempCode = null; string error = null; int time = 0; HttpWebResponse response = null; HttpWebRequest request = null; do //访问失败时重新访问,最多重新访问4次 { WebProxy proxy = new WebProxy("代理网站", false); proxy.Credentials = new NetworkCredential(@"用户名", "密码", ""); request = HttpWebRequest.Create(uri.AbsoluteUri) as HttpWebRequest; Thread.Sleep(30); request.AllowAutoRedirect = true; request.Proxy = proxy; //使用了代理 int a = 0; time += 1; error = null; try { DateTime now = DateTime.Now; response = request.GetResponse() as HttpWebResponse; TimeSpan t = DateTime.Now - now; } catch (Exception ex) { tempCode = ex.Message; error = ex.Message; } } while (error != null && time < 4); System.IO.Stream resStream = null; StreamReader sr = null; try { resStream = response.GetResponseStream(); sr = new StreamReader(resStream, Encoding.UTF8); tempCode = sr.ReadToEnd(); response.Close(); resStream.Close(); sr.Close(); } catch (Exception e) {} return tempCode; }