Web代理(Asp版)
程序员文章站
2022-04-14 18:53:41
asp写web代理软件,可以用作突破网关限制等,主要是为了配合ajax使用的(因firefox存在跨域访问的问题) 版本 0.1 作者 llinzzi...
asp写web代理软件,可以用作突破网关限制等,主要是为了配合ajax使用的(因firefox存在跨域访问的问题) 版本 0.1 作者 llinzzi
功能
判断网站编码,支持任何语言
超连接自动转换
附带一个远程下载图片的函数
未解决问题,目前只能用来代理网站代码,图片等其他数据的代理转发尚未完成。
<%@language="javascript" codepage="65001"%>
<%response.charset = "utf-8"%>
<%
server.scripttimeout=9999999;
var surl = string(request.querystring("url"));
if(surl == "undefined"){
response.write("<p style=\"font-size:9pt;margin:30px;padding:10px;text-align:center;background-color:#ffcccc;border: 1px solid #999999;\">asp代理 by llinzzi</p>");
response.write("<div style=\"font-size:9pt;margin:30px;text-align:center;background-color:#ffffcc;border: 1px solid #999999;\">");
response.write("<form action=\"#\" method=\"get\" >");
response.write("<p style=\"font-size:9pt;margin:5px;text-align:center;\">请输入网址</p>");
response.write("<p><input style=\"background-color: #ffcccc;border: 1px solid #999999;\" type=\"text\" name=\"url\"></p>");
response.write("<p><input style=\"background-color: #ffcccc;border: 1px solid #999999;\" type=\"submit\" value=\"goweb\"></p>");
response.write("</div>");
}
else if(surl == ""){
response.write("<p style=\"font-size:9pt;margin:30px;padding:10px;text-align:center;background-color:#ffcccc;border: 1px solid #999999;\">asp代理 by llinzzi</p>");
response.write("<div style=\"font-size:9pt;margin:30px;text-align:center;background-color:#ffffcc;border: 1px solid #999999;\">");
response.write("<p>地址为空,请格式输入 如 www.tom.com </p>");
response.write("</div>");
}
else{
surl = (surl.substr(0,7) != "http://") ? "http://"+surl : surl;
response.write(send_request(surl));
}
function send_request(url) {
var codedtext;
http_request = server.createobject("microsoft.xmlhttp");
try{
http_request.open("get",url,false);
http_request.send(null);
}
catch(e)
{
response.write(e.description);
}
if (http_request.readystate == 4){
//自动判断编码开始
var charresult = http_request.responsetext.match(/charset=(\s+)"/i);
if (charresult != null){
var cset = charresult[1];
}else{cset = "utf-8"}
//自动判断编码结束
codedtext = bytestobstr(http_request.responsebody,cset);
}else{
codedtext = "erro";
}
//替换超连接
codedtext = codedtext.replace(/href="\/?/ig,"href=\""+url+"/");
codedtext = codedtext.replace(/(<a.*href=")/ig,"$1servergate.asp?url=");
return(codedtext);
}
function bytestobstr(body,cset){
var objstream;
objstream = server.createobject("adodb.stream");
objstream.type = 1;
objstream.mode = 3;
objstream.open();
objstream.write(body);
objstream.position = 0;
objstream.type = 2;
objstream.charset = cset;
bytestobstr = objstream.readtext;
objstream.close;
return(bytestobstr);
}
function saveremotefile(localfilename,remotefileurl){
var retrieval,ads;
retrieval = server.createobject("microsoft.xmlhttp");
retrieval.open("get",remotefileurl,false);
retrieval.send(null);
if (retrieval.readystate == 4){
ads = server.createobject("adodb.stream");
ads.type = 1;
ads.open();
ads.write(retrieval.responsebody);
ads.savetofile(server.mappath(localfilename),2);
ads.cancel;
ads.close;
}
}
//saveremotefile("aa.gif","http://www.baidu.com/img/logo.gif");
%>
功能
判断网站编码,支持任何语言
超连接自动转换
附带一个远程下载图片的函数
未解决问题,目前只能用来代理网站代码,图片等其他数据的代理转发尚未完成。
复制代码 代码如下:
<%@language="javascript" codepage="65001"%>
<%response.charset = "utf-8"%>
<%
server.scripttimeout=9999999;
var surl = string(request.querystring("url"));
if(surl == "undefined"){
response.write("<p style=\"font-size:9pt;margin:30px;padding:10px;text-align:center;background-color:#ffcccc;border: 1px solid #999999;\">asp代理 by llinzzi</p>");
response.write("<div style=\"font-size:9pt;margin:30px;text-align:center;background-color:#ffffcc;border: 1px solid #999999;\">");
response.write("<form action=\"#\" method=\"get\" >");
response.write("<p style=\"font-size:9pt;margin:5px;text-align:center;\">请输入网址</p>");
response.write("<p><input style=\"background-color: #ffcccc;border: 1px solid #999999;\" type=\"text\" name=\"url\"></p>");
response.write("<p><input style=\"background-color: #ffcccc;border: 1px solid #999999;\" type=\"submit\" value=\"goweb\"></p>");
response.write("</div>");
}
else if(surl == ""){
response.write("<p style=\"font-size:9pt;margin:30px;padding:10px;text-align:center;background-color:#ffcccc;border: 1px solid #999999;\">asp代理 by llinzzi</p>");
response.write("<div style=\"font-size:9pt;margin:30px;text-align:center;background-color:#ffffcc;border: 1px solid #999999;\">");
response.write("<p>地址为空,请格式输入 如 www.tom.com </p>");
response.write("</div>");
}
else{
surl = (surl.substr(0,7) != "http://") ? "http://"+surl : surl;
response.write(send_request(surl));
}
function send_request(url) {
var codedtext;
http_request = server.createobject("microsoft.xmlhttp");
try{
http_request.open("get",url,false);
http_request.send(null);
}
catch(e)
{
response.write(e.description);
}
if (http_request.readystate == 4){
//自动判断编码开始
var charresult = http_request.responsetext.match(/charset=(\s+)"/i);
if (charresult != null){
var cset = charresult[1];
}else{cset = "utf-8"}
//自动判断编码结束
codedtext = bytestobstr(http_request.responsebody,cset);
}else{
codedtext = "erro";
}
//替换超连接
codedtext = codedtext.replace(/href="\/?/ig,"href=\""+url+"/");
codedtext = codedtext.replace(/(<a.*href=")/ig,"$1servergate.asp?url=");
return(codedtext);
}
function bytestobstr(body,cset){
var objstream;
objstream = server.createobject("adodb.stream");
objstream.type = 1;
objstream.mode = 3;
objstream.open();
objstream.write(body);
objstream.position = 0;
objstream.type = 2;
objstream.charset = cset;
bytestobstr = objstream.readtext;
objstream.close;
return(bytestobstr);
}
function saveremotefile(localfilename,remotefileurl){
var retrieval,ads;
retrieval = server.createobject("microsoft.xmlhttp");
retrieval.open("get",remotefileurl,false);
retrieval.send(null);
if (retrieval.readystate == 4){
ads = server.createobject("adodb.stream");
ads.type = 1;
ads.open();
ads.write(retrieval.responsebody);
ads.savetofile(server.mappath(localfilename),2);
ads.cancel;
ads.close;
}
}
//saveremotefile("aa.gif","http://www.baidu.com/img/logo.gif");
%>
上一篇: FSO一些代码
推荐阅读
-
asp.net textbox 属性value没有值_html/css_WEB-ITnose
-
网络寻呼机数据库版显示消息showmessage.asp
-
win2008 R2 WEB环境配置之MYSQL 5.6.22安装版安装配置方法_MySQL
-
ASP.NET Web Pages - PHP
-
ASP.NET Web Pages - WebMail 对象
-
将会员注册页面的Email修改成非必填项(ecshop2.7.2版)_html/css_WEB-ITnose
-
asp.net web页面自定义分页控件使用详解
-
创建一个完整的ASP.NET Web API项目
-
ASP.NET Web API如何将注释自动生成帮助文档
-
ASP.NET如何使用web服务的会话状态