ASP converts the web page encoding code, uses regular matching to determine whether the encoding statement of the page is gb2312 or other, and then outputs it. The complete sample code is as follows:
Copy the code code as follows:
<%@LANGUAGE=JAVASCRIPT CODEPAGE=65001%>
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=utf-8>
<title>JavaScript automatically determines the web page encoding and converts it</title>
</head>
<%Server.ScriptTimeout=9999999;
function send_request(url){
var codedtext;
http_request = Server.CreateObject(Microsoft.XMLHTTP);
http_request.Open(GET,url,false);
http_request.Send(null);
if (http_request.ReadyState == 4){
//Automatically determine the start of encoding
var charresult = http_request.ResponseText.match(/CharSet=(/S+)/>/i);
if (charresult != null){
var Cset = charresult[1];
}else{Cset = gb2312}//Adopt gb2312 encoding for websites that cannot be obtained, and you can change it yourself
//Automatically determine the end of encoding
codedtext = bytesToBSTR(http_request.Responsebody,Cset);
}else{
codedtext = Erro;
}
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);
}%>
<body>
<%Response.Write(send_request(http://www.vevb.com/404.htm))%>
</body>
</html>