无为清净楼资源网 Design By www.qnjia.com
本文仅针AD下代理上网的情况:
代码如下:
1、定义变量:
定义变量#region 定义变量
复制代码 代码如下:
private string strFireWallIP
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strFireWallIP"];
}
}
private string strFireWallPort
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strFireWallPort"];
}
}
private string strUID
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strUID"];
}
}
private string strPWD
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strPWD"];
}
}
private string strDomain
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strDomain"];
}
}
#endregion
方法:
获取指定远程网页内容
复制代码 代码如下:
/**//// <summary>
/// 获取指定远程网页内容
/// </summary>
/// <param name="strUrl">所要查找的远程网页地址</param>
/// <returns></returns>
//[WebMethod(Description = "获取指定远程网页内容。")]
public string getPageContent(string strUrl)
...{
string strResult = "";
this.CurrentUrl = strUrl;
if(this.CurrentUrl.ToLower().StartsWith("http://")==false)
this.CurrentUrl = "http://"+this.CurrentUrl;
try
...{
contentBytes = GetHtmlByte(CurrentUrl);
}
catch(Exception err)
...{
strResult = "请求错误:" + err.Message;
}
if(contentBytes==null)
...{
throw new Exception("没有获得返回值");
}
strResult = getStringFromByteArray(contentBytes,Encoding.UTF8);
return strResult;
}
获取指定远程网页元素字节数组::
获取指定远程网页元素字节数组#region 获取指定远程网页元素字节数组
复制代码 代码如下:
/**//// <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 转换指定字节数组为字符串
复制代码 代码如下:
/**//// <summary>
/// 转换指定字节数组为字符串
/// </summary>
/// <param name="ByteGet">字节数组Byte[]</param>
/// <param name="myEncoding">编码方式</param>
/// <returns></returns>
private static string getStringFromByteArray(Byte[] ByteGet,Encoding myEncoding)
...{
int i,lngCount;
StringBuilder aTemp = new StringBuilder(10000);
lngCount = ByteGet.Length;
for(i = 0;i<lngCount;i+= 10000)
...{
aTemp.Append(myEncoding.GetString(ByteGet,i,(lngCount>=i+10000?10000:lngCount - i)));
}
if(i<=lngCount)
...{
aTemp.Append(myEncoding.GetString(ByteGet,i,(lngCount - i)));
}
return aTemp.ToString();
}
#endregion
借用这个,写了个抽取中国天气网预报的服务!很爽!
代码如下:
1、定义变量:
定义变量#region 定义变量
复制代码 代码如下:
private string strFireWallIP
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strFireWallIP"];
}
}
private string strFireWallPort
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strFireWallPort"];
}
}
private string strUID
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strUID"];
}
}
private string strPWD
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strPWD"];
}
}
private string strDomain
...{
get
...{
return System.Configuration.ConfigurationSettings.AppSettings["strDomain"];
}
}
#endregion
方法:
获取指定远程网页内容
复制代码 代码如下:
/**//// <summary>
/// 获取指定远程网页内容
/// </summary>
/// <param name="strUrl">所要查找的远程网页地址</param>
/// <returns></returns>
//[WebMethod(Description = "获取指定远程网页内容。")]
public string getPageContent(string strUrl)
...{
string strResult = "";
this.CurrentUrl = strUrl;
if(this.CurrentUrl.ToLower().StartsWith("http://")==false)
this.CurrentUrl = "http://"+this.CurrentUrl;
try
...{
contentBytes = GetHtmlByte(CurrentUrl);
}
catch(Exception err)
...{
strResult = "请求错误:" + err.Message;
}
if(contentBytes==null)
...{
throw new Exception("没有获得返回值");
}
strResult = getStringFromByteArray(contentBytes,Encoding.UTF8);
return strResult;
}
获取指定远程网页元素字节数组::
获取指定远程网页元素字节数组#region 获取指定远程网页元素字节数组
复制代码 代码如下:
/**//// <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 转换指定字节数组为字符串
复制代码 代码如下:
/**//// <summary>
/// 转换指定字节数组为字符串
/// </summary>
/// <param name="ByteGet">字节数组Byte[]</param>
/// <param name="myEncoding">编码方式</param>
/// <returns></returns>
private static string getStringFromByteArray(Byte[] ByteGet,Encoding myEncoding)
...{
int i,lngCount;
StringBuilder aTemp = new StringBuilder(10000);
lngCount = ByteGet.Length;
for(i = 0;i<lngCount;i+= 10000)
...{
aTemp.Append(myEncoding.GetString(ByteGet,i,(lngCount>=i+10000?10000:lngCount - i)));
}
if(i<=lngCount)
...{
aTemp.Append(myEncoding.GetString(ByteGet,i,(lngCount - i)));
}
return aTemp.ToString();
}
#endregion
借用这个,写了个抽取中国天气网预报的服务!很爽!
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- 群星《天域原音·聆听雪域藏歌STS+SRS》[WAV+CUE]
- 尤长靖.2020-AZORAland·我是尤长靖【香蕉娱乐】【FLAC分轨】
- 群星.1995-台北爱情故事【飞碟】【WAV+CUE】
- 群星.2024-锦绣安宁电视剧原声带【D-Jin.Music】【FLAC分轨】
- 群星《闪光的夏天 第4期》[320K/MP3][97.82MB]
- 群星《闪光的夏天 第4期》[FLAC/分轨][553.31MB]
- 群星《奔赴!万人现场 第4期》[320K/MP3][80.75MB]
- 林琳《独角戏HQ》WAV
- FIM-《Super-Sound-3》声霸3[WAV+CUE]
- 喇叭花-绝版天碟《我的碟“MyDisc”》[正版原抓WAV+CUE]
- 陈慧琳.1999-真感觉【正东】【WAV+CUE】
- 徐玮.1986-走自己的路(喜玛拉雅复刻版)【同心圆】【WAV+CUE】
- 林海峰.2003-我撑你【EMI百代】【WAV+CUE】
- 群星《奔赴!万人现场 第4期》[FLAC/分轨][454.89MB]
- 腾讯音乐人《未来立体声·Stereo Future VOL.12》[320K/MP3][62.37MB]