#region testget
void GetResponseCallback(IAsyncResult ar)
{
try
{
HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
//HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar);
InitResponseText();
if (IsImg)
{
Image img;
img = new System.Drawing.Bitmap(response.GetResponseStream());
img.Save(ImgName);
img.Dispose();
}
else
{
Stream resStream = response.GetResponseStream();
Encoding encode = GetEncoding;
StreamReader readStream = new StreamReader(resStream, encode);
HtmlText = readStream.ReadToEnd();
for (int i = 0; i < response.Headers.Count; i++)
HeaderText += response.Headers.GetKey(i) + ": " + response.Headers[i] + "\r\n";
if (GetCookieMode)
{
for (int i = 0; i < response.Cookies.Count; i++)
CookieText += response.Cookies[i].Name + "=" + response.Cookies[i].Value + ";";
}
resStream.Close();
readStream.Close();
resStream.Dispose();
readStream.Dispose();
}
}
catch (Exception ex) { Console.WriteLine(ex); }
}
public void HttpGet()
{
try
{
Uri uri = new Uri(URLData);
ServicePointManager.DefaultConnectionLimit = ConnectLimit;
ServicePointManager.UseNagleAlgorithm = false;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.UnsafeAuthenticatedConnectionSharing = true;
request.ServicePoint.ConnectionLimit = ConnectLimit;
request.ServicePoint.Expect100Continue = false;
request.ServicePoint.UseNagleAlgorithm = false;
request.Method = "GET";
request.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, */*";
if (RefData != "")
{
request.Referer = RefData;
}
request.Headers.Add("Accept-Language", "zh-cn");
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)";
request.Headers.Add("Expires", "0");
request.AllowAutoRedirect = AutoRedirect;
request.AutomaticDecompression = DecompressionMethods.GZip;
request.AllowWriteStreamBuffering = false;
request.Timeout = TimeOut;
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
request.KeepAlive = true;
if (GetCookieMode)
{
request.CookieContainer = new CookieContainer();
if (CookieData != "")
{
string[] tmpCookie = CookieData.Split(';');
for (int i = 0; i < tmpCookie.Length; i++)
if (tmpCookie[i] != "")
{
string[] setCookie = tmpCookie[i].Split(new Char[] { '=' }, 2);
request.CookieContainer.Add(uri, new Cookie(setCookie[0], setCookie[1]));
}
}
}
else
{
if (CookieData != "")
request.Headers.Add("Cookie", CookieData);
}
HttpWebResponse response = (HttpWebResponse)request.BeginGetResponse(GetResponseCallback, request);
allDone.WaitOne();
}
catch (Exception ee)
{
HtmlText = ee.Message;// "Error";
}
}
#endregion