日期:2013-04-27  浏览次数:20511 次



调用方式:

#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

{

/// <summary>

/// 功能:取得Internet上的URL页的源码

/// 创建:2004-03-22

/// 作者:Rexsp MSN:yubo@x263.net

/// </summary>

public class GetPageCode

{

#region 私有变量

/// <summary>

/// 网页URL地址

/// </summary>

private string url=null;

/// <summary>

/// 是否使用代码服务器:0 不使用 1 使用代理服务器

/// </summary>

private int proxyState=0;

/// <summary>

/// 代理服务器地址

/// </summary>

private string proxyAddress=null;

/// <summary>

/// 代理服务器端口

/// </summary>

private string proxyPort=null;

/// <summary>

/// 代理服务器用户名

/// </summary>

private string proxyAccount=null;

/// <summary>

/// 代理服务器密码

/// </summary>

private string proxyPassword=null;

/// <summary>

/// 代理服务器域

/// </summary>

private string proxyDomain=null;

/// <summary>

/// 输出文件路径

/// </summary>

private string outFilePath=null;

/// <summary>

/// 输出的字符串

/// </summary>

private string outString=null;

/// <summary>

/// 提示信息

/// </summary>

private string noteMessage;



#endregion



#region 公共属性

/// <summary>

/// 欲读取的URL地址

/// </summary>

public string Url

{

get{return url;}

set{url=value;}

}

/// <summary>

/// 是否使用代理服务器标志

/// </summary>

public int ProxyState

{

get{return proxyState;}

set{proxyState=value;}

}

/// <summary>

/// 代理服务器地址

/// </summary>

public string ProxyAddress

{

get{return proxyAddress;}

set{proxyAddress=value;}

}

/// <summary>

/// 代理服务器端口

/// </summary>

public string ProxyPort

{