<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) <= 0 Then
        charset = "utf-8"
    End If
    
    If Len(sRSSUrl) > 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) > 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) > 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 = ""
        sXML = sXML & ""
        sXML = sXML & ""
        sXML = sXML & "没有指定RSS源"
        sXML = sXML & "http://www.myfootprints.cn"
        sXML = sXML & ""
        sXML = sXML & "http://www.myfootprints.cn/images/logo.gif"
        sXML = sXML & "没有指定RSS源"
        sXML = sXML & "http://www.myfootprints.cn"
        sXML = sXML & "100"
        sXML = sXML & "50"
        sXML = sXMl & ""
        sXML = sXMl & "没有指定RSS源"
        sXML = sXMl & "zh-cn"
        sXML = sXML & "[email protected]"
        sXML = sXML & "我的涂鸦"
        sXML = sXMl & "Copyright 2009 我的涂鸦"
        sXML = sXML & ""
        sXML = sXML & "没有指定RSS源"
        sXML = sXML & "http://www.myfootprints.cn"
        sXML = sXML & "http://www.myfootprints.cn/newsfeeder.asp"
        sXML = sXML & "Jeff Tian <[email protected]>"
        sXML = sXML & "2009-11-15T21:07:00-21:20"
        sXML = sXML & ""
        sXML = sXML & ""
        sXML = sXML & ""
        Response.Write sXML
    End If
%>