Web代理(Asp版)(2)
//自动判断编码开始
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");
%>