调用方式:
#region 测试获取远程网页
GetPageCode gpc = new GetPageCode();
gpc.Url="http://ppcode.com/";
gpc.ProxyState=1; //使用代理服务器,0为不使用,设置为1后下面的代理设置才起作用
gpc.ProxyAddress="http://proxyName.com"; //代理服务器地址
gpc.ProxyPort="80"; //代理服务器的端口
gpc.ProxyAccount="proxy"; //代理服务器账号
gpc.ProxyPassword="password"; //代理服务器密码
gpc.ProxyDomain="bqc"; //代理服务器域
gpc.OutFilePath=filePath; //设置输出文件路径的地方,如果不设置,则返回字符串
gpc.GetSource(); //处理
string tempErr=gpc.NoteMessage; //如果出错,这里会提示
string tempCode=gpc.OutString; //返回的字符串
#endregion
类代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
namespace Test.Com
{
///
1<summary>
2
3/// 功能:取得Internet上的URL页的源码
4
5/// 创建:2004-03-22
6
7/// 作者:Rexsp MSN:[email protected]
8
9/// </summary>
public class GetPageCode
{
#region 私有变量
///
1<summary>
2
3/// 网页URL地址
4
5/// </summary>
private string url= null ;
///
1<summary>
2
3/// 是否使用代码服务器:0 不使用 1 使用代理服务器
4
5/// </summary>
private int proxyState=0;
///
1<summary>
2
3/// 代理服务器地址
4
5/// </summary>
private string proxyAddress= null ;
///
1<summary>
2
3/// 代理服务器端口
4
5/// </summary>
private string proxyPort= null ;
///
1<summary>
2
3/// 代理服务器用户名
4
5/// </summary>
private string proxyAccount= null ;
///
1<summary>
2
3/// 代理服务器密码
4
5/// </summary>
private string proxyPassword= null ;
///
1<summary>
2
3/// 代理服务器域
4
5/// </summary>
private string proxyDomain= null ;
///
1<summary>
2
3/// 输出文件路径
4
5/// </summary>
private string outFilePath= null ;
///
1<summary>
2
3/// 输出的字符串
4
5/// </summary>
private string outString= null ;
///
1<summary>
2
3/// 提示信息
4
5/// </summary>
private string noteMessage;
#endregion
#region 公共属性
///
1<summary>
2
3/// 欲读取的URL地址
4
5/// </summary>
public string Url
{
get { return url;}
set {url= value ;}
}
///
1<summary>
2
3/// 是否使用代理服务器标志
4
5/// </summary>
public int ProxyState
{
get { return proxyState;}
set {proxyState= value ;}
}
///
1<summary>
2
3/// 代理服务器地址
4
5/// </summary>
public string ProxyAddress
{
get { return proxyAddress;}
set {proxyAddress= value ;}
}
///
1<summary>
2
3/// 代理服务器端口
4
5/// </summary>
public string ProxyPort
{
get { return proxyPort;}
set {proxyPort= value ;}
}
///
1<summary>
2
3/// 代理服务器账号
4
5/// </summary>
public string ProxyAccount
{
get { return proxyAccount;}
set {proxyAccount= value ;}
}
///
1<summary>
2
3/// 代理服务器密码
4
5/// </summary>
public string ProxyPassword
{
get { return proxyPassword;}
set {proxyPassword= value ;}
}
///
1<summary>
2
3/// 代理服务器域
4
5/// </summary>
public string ProxyDomain
{
get { return proxyDomain;}
set {proxyDomain= value ;}
}
///
1<summary>
2
3/// 输出文件路径
4
5/// </summary>
public string OutFilePath
{
get { return outFilePath;}
set {outFilePath= value ;}
}
///
1<summary>
2
3/// 返回的字符串
4
5/// </summary>
public string OutString
{
get { return outString;}
}
///
1<summary>
2
3<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layo</summary>