Web 在线代理的 ASP 版!(开源)

[复制链接]
查看: 1158   回复: 0
发表于 2007-4-16 10:39:50 | 显示全部楼层 |阅读模式
  1. <%@LANGUAGE="JavaSCRIPT" CODEPAGE="65001"%>
  2. <%Response.Charset = "utf-8"%>
  3. <%
  4. Server.ScriptTimeout=9999999;
  5. var Surl = String(Request.QueryString("url"));
  6. if(Surl == "undefined"){
  7. Response.Write("<p style="font-size:9pt;margin:30px;padding:10px;text-align:center;background-color:#FFCCCC;border: 1px solid #999999;">金光论坛 ASP WEB 在线代理程序 1.0 版</p>");
  8. Response.Write("<div style="font-size:9pt;margin:30px;text-align:center;background-color:#FFFFCC;border: 1px solid #999999;">");
  9. Response.Write("<form action="#" method="get" >");
  10. Response.Write("<p style="font-size:9pt;margin:5px;text-align:center;">请键入网址</p>");
  11. Response.Write("<p><input style="background-color: #FFCCCC;border: 1px solid #999999;" type="text" name="url"></p>");
  12. Response.Write("<p><input style="background-color: #FFCCCC;border: 1px solid #999999;" type="submit"  value="GoWeb"></p>");
  13. Response.Write("</div>");
  14. }
  15. else if(Surl == ""){
  16. Response.Write("<p style="font-size:9pt;margin:30px;padding:10px;text-align:center;background-color:#FFCCCC;border: 1px solid #999999;">金光论坛 ASP WEB 在线代理程序 1.0 版</p>");
  17. Response.Write("<div style="font-size:9pt;margin:30px;text-align:center;background-color:#FFFFCC;border: 1px solid #999999;">");
  18. Response.Write("<p>您需要键入一个网址!例如: bbs.jgwy.net </p>");
  19. Response.Write("</div>");
  20. }
  21. else{
  22. Surl = (Surl.substr(0,7) != "http://") ? "http://"+Surl : Surl;
  23. Response.Write(send_request(Surl));
  24. }
  25. function send_request(url) {
  26.     var codedtext;
  27.     http_request = Server.CreateObject("Microsoft.XmlHTTP");
  28.     try{
  29.     http_request.Open("GET",url,false);
  30.     http_request.Send(null);
  31.     }
  32.     catch(e)
  33.     {
  34.     Response.Write(e.description);
  35.     }
  36.     if (http_request.ReadyState == 4){
  37.         //自动判断编码开始
  38.         var charresult = http_request.ResponseText.match(/CharSet=(\S+)"/i);
  39.         if (charresult != null){
  40.         var Cset = charresult[1];
  41.         }else{Cset = "utf-8"}
  42.         //自动判断编码结束
  43.         codedtext = bytesToBSTR(http_request.Responsebody,Cset);
  44.         }else{
  45.         codedtext = "Erro";
  46.         }
  47.         //替换超连接
  48.         codedtext = codedtext.replace(/href="\/?/ig,"href=""+url+"/");
  49.         codedtext = codedtext.replace(/(<a.*href=")/ig,"$1index.asp?url=");
  50.     return(codedtext);
  51. }
  52. function bytesToBSTR(body,Cset){
  53.     var objstream;
  54.     objstream = Server.CreateObject("Adodb.Stream");
  55.     objstream.Type = 1;
  56.     objstream.Mode = 3;
  57.     objstream.Open();
  58.     objstream.Write(body);
  59.     objstream.Position = 0;
  60.     objstream.Type = 2;
  61.     objstream.Charset = Cset;
  62.     bytesToBSTR = objstream.Readtext;
  63.     objstream.Close;
  64.     return(bytesToBSTR);
  65. }
  66. function SaveRemoteFile(LocalFileName,RemoteFileUrl){
  67.     var Retrieval,Ads;
  68.     Retrieval = Server.CreateObject("Microsoft.XmlHTTP");
  69.     Retrieval.Open("GET",RemoteFileUrl,false);
  70.     Retrieval.Send(null);
  71.     if (Retrieval.ReadyState == 4){
  72.     Ads = Server.CreateObject("Adodb.Stream");
  73.     Ads.Type = 1;
  74.     Ads.Open();
  75.     Ads.Write(Retrieval.Responsebody);
  76.     Ads.SaveToFile(Server.MapPath(LocalFileName),2);
  77.     Ads.Cancel;
  78.     Ads.Close;
  79.     }
  80. }
  81. //SaveRemoteFile("aa.gif","/XrssFile/2007-1/12/2007112124640411.gif");
  82. %>
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则