<% @LANGUAGE = "JAVASCRIPT" codepage= "65001"%>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>asp automatically Judge page encoding and conversion </title>
<%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) {
Automatic Judgment Coding Start
var charresult = http_request. Responsetext.match (/charset= (s+) ">/i");
if (Charresult!= null) {
var Cset = charresult[1];
}else{cset = "gb2312"}//is gb2312 encoded for Web sites that are not available and can be changed by itself
Automatic Judgment Coding End
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.111cn.net/404.htm"))%>
</body>
The principle of acquisition is very simple to use the ASP XMLHTTP to collect, and ADODB.stream to the collection of data processing.