/**//// <summary>
/// 获取指定远程网页元素字节数组
/// </summary>
/// <param name="strUrl">所要查找的远程网页地址</param>
/// <returns></returns>
private byte[] GetHtmlByte(string strUrl)
...{
string strPara=(strUrl.IndexOf("?")>=0?strUrl.Substring(strUrl.IndexOf("?")+1):"");
System.Text.Encoding encoding = new UTF8Encoding();
byte[] byte1 = encoding.GetBytes(strPara);
byte[] byteReturn = new byte[10000000];
if(strUrl.Trim().ToLower().StartsWith("http://")==false)
...{
strUrl = "http://"+strUrl;
}
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myHttpWebRequest.AllowAutoRedirect = true;
myHttpWebRequest.KeepAlive = true;
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
System.Net .WebProxy proxy = new WebProxy(strFireWallIP+":"+strFireWallPort,true);
//proxy=(WebProxy)System.Net.GlobalProxySelection.Select;
System.Net.NetworkCredential myCredential = new NetworkCredential(strUID,strPWD,strDomain);
proxy.Credentials =myCredential;
myHttpWebRequest.Proxy = proxy;
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
byte[] bRead = new byte[1024];
int lngCount = 1;
int totalLen = 0;
Stream recWeb = myHttpWebResponse.GetResponseStream();
lngCount = recWeb.Read(bRead,0,1024);
while(lngCount>0)
...{
Array.Copy(bRead,0,byteReturn,totalLen,lngCount);
totalLen += lngCount;
lngCount = recWeb.Read(bRead,0,1024);
}
recWeb.Close();
byte[] byteGets = new byte[totalLen];
Array.Copy(byteReturn,0,byteGets,0,totalLen);
byteReturn = null;
bRead = null;
return byteGets;
}
#endregion
转换指定字节数组为字符串::
转换指定字节数组为字符串#region 转换指定字节数组为字符串
复制代码 代码如下: