<div style="text-indent: 2em; font-size: larger;">

网页代理就是浏览器客户端与目的服务器端的一个中间者,本来浏览器直接向服务器请求文件,然后服务器将请求的文件内容直接传回浏览器端。增加了网页代理后,浏览器客户端先将要请求的文件信息发给代理,代理再将请求信息转发给目的服务器;目的服务器又将相应的响应内容发回给代理,代理再将此内容转发回浏览器客户端。

这样有什么用?干嘛没事儿找事儿增加一个代理呢?

至少有两个地方正在使用着它。

一、RSS新闻聚合器。比如Google的阅读器(http://www.google.com/reader)。

二、新闻采集程序或者说“小偷”程序。

我在上篇文章《不登录也可以阅读华尔街日报网文章》中,就使用了网页代理来查看华尔街日报网的那些好像不能够被查看的文章。它相当于是一个简单的新闻采集程序的雏形。那个网页代理的源码是:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>
<%Session.CodePage=65001%>
<%
    Response.CharSet = "utf-8"
%>
<%
    Response.ContentType = "text/html"
    Dim sRSSUrl, oHTTP, charset
    sRSSUrl = Request.QueryString("url")
    charset = Request.QueryString("charset")
If Len(charset) &lt;= 0 Then
    charset = "utf-8"
End If

If Len(sRSSUrl) &gt; 0 Then

    Set oHTTP = Server.CreateObject("Microsoft.XMLHTTP")
    oHTTP.Open "GET", sRSSURL, False
    oHTTP.Send
    
    Response.Write Cbns2TextStream(oHTTP.ResponseBody, charset)
    Set oHTTP = Nothing
Else
    Response.Write ""
End If

%> <% ' ' 将指定的二进制串转换成特定编码的文本 ' Public Function Cbns2TextStream(ByRef bns, ByRef sCharset) Dim stm

    Set stm = Server.CreateObject("ADODB.Stream")
    stm.Type = 2
    stm.Open
    stm.WriteText bns
    stm.Position = 0
    If Len(sCharset) &gt; 0 Then stm.Charset = sCharset
    Cbns2TextStream = stm.ReadText
    stm.Close
    Set stm = Nothing
End Function 

%>

它接受两个参数,一个网址,一个编码格式(若为空,则默认是utf-8)。        

对于RSS新闻阅读器,本站的名人最新动态(http://www.myfootprints.cn/FamousBlog.asp),也可看作是它的一个简单雏形。其中用到的代理源代码是:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>
<%Session.CodePage=65001%>
<%
    Response.CharSet = "utf-8"
%>
<%
    Response.ContentType = "text/xml"
    Dim sRSSUrl, oHTTP
    sRSSUrl = Request.QueryString("rssurl")
If Len(sRSSUrl) &gt; 0 Then

    Set oHTTP = Server.CreateObject("Microsoft.XMLHTTP")
    oHTTP.Open "GET", sRSSURL, False
    oHTTP.Send
    
    Response.Write oHTTP.ResponseXML.XML
    Set oHTTP = Nothing
Else
    Dim sXML
    sXML = "<!--?xml version=""1.0"" encoding=""utf-8""?-->"
    sXML = sXML &amp; "<rss version="" 2.0""="" xmlns:dc="" http:="" purl.org="" dc="" elements="" 1.1="" ""="">"
    sXML = sXML &amp; "<channel>"
    sXML = sXML &amp; "<title>没有指定RSS源</title>"
    sXML = sXML &amp; "<link>http://www.myfootprints.cn"
    sXML = sXML &amp; "<img>"
    sXML = sXML &amp; "<url>http://www.myfootprints.cn/images/logo.gif</url>"
    sXML = sXML &amp; "<title>没有指定RSS源</title>"
    sXML = sXML &amp; "<link>http://www.myfootprints.cn"
    sXML = sXML &amp; "<width>100</width>"
    sXML = sXML &amp; "<height>50</height>"
    sXML = sXMl &amp; ""
    sXML = sXMl &amp; "<description>没有指定RSS源</description>"
    sXML = sXMl &amp; "<language>zh-cn</language>"
    sXML = sXML &amp; "<managingeditor>admin@myfootprints.cn</managingeditor>"
    sXML = sXML &amp; "<dc:publisher>我的涂鸦</dc:publisher>"
    sXML = sXMl &amp; "<copyright>Copyright 2009 我的涂鸦</copyright>"
    sXML = sXML &amp; "<item>"
    sXML = sXML &amp; "<title>没有指定RSS源</title>"
    sXML = sXML &amp; "<link>http://www.myfootprints.cn"
    sXML = sXML &amp; "<guid>http://www.myfootprints.cn/newsfeeder.asp</guid>"
    sXML = sXML &amp; "<author>Jeff Tian &lt;admin@myfootprints.cn&gt;</author>"
    sXML = sXML &amp; "<dc:date>2009-11-15T21:07:00-21:20</dc:date>"
    sXML = sXML &amp; "</item>"
    sXML = sXML &amp; "</channel>"
    sXML = sXML &amp; "</rss>"
    Response.Write sXML
End If

%>