基于asp.net的跨域访问代理文件c#代码如下:
@ Page Language="C#" AutoEventWireup="true" ResponseEncoding="utf-8" %>
@ Import Namespace=System.Net %>
@ Import Namespace=System.IO %>
script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
string sourceUrl = "http://devspy.net";
this.Page.Response.Write(TransferHtmlPage(string.Concat(sourceUrl, "?", this.Page.Request.QueryString)));
}
public string TransferHtmlPage(string url)
{
string result = string.Empty;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
result = reader.ReadToEnd();
}
catch(Exception ex)
{
return string.Format(@"
服务器获取文件内容出错:{0}
", ex.Message);}
if (!CheckVersionWaterMark(result))
return @"
版本水印失效,请联系相关技术人员。
";return result;
}
public bool CheckVersionWaterMark(string inputString)
{
return true;//不验证水印了
//string pattern = "WaterMark";
//return Regex.IsMatch(inputString, pattern, RegexOptions.IgnoreCase);
}
script>
另外还有基于asp和php的实现,不再列出,感兴趣的可以下载包含这三个文件的压缩包:
http://files.cnblogs.com/cncxz/ajaxProxy.rar