起因,只要我通过Microsoft.XMLHTTP去获取某url的值,瑞典字符都变成乱码。如果不通过XMLHTTP就是正常的。
所有的系统设置请参考:http://topic.csdn.net/u/20080711/17/d30de8f4-9b4e-4f15-91bb-b2dd2969614e.html
两个帖属于同一问题,两个帖的分都可以给大家。第一种方法:如下方式obj.setRequestHeader如果放在open方法之前js报错, 如果放在之后,不起作用 ?
第二种:对obj.responseStream操作,采用ADODB.Stream, 用合适的编码转化出来 ?
第三种:在js中是否还有其它的连网方式,就是不用XMLHTTP ?
第四种:在asp中采用某种连网方式去获取数据 ?var obj = new ActiveXObject("Microsoft.XMLHTTP");
//var obj = new ActiveXObject("MSXML2.ServerXMLHTTP");
//var obj = new ActiveXObject("Msxml2.XMLHTTP"); //obj.setRequestHeader("Content-Type", "text/xml");

// Submit the request
obj.open("GET", url, false);
obj.setRequestHeader("charset", "iso-8859-1");
obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
obj.setRequestHeader( "Char-Set", "iso-8859-1");
obj.send();
//alert(obj.CharSet);
//alert(obj.responseText);
//alert(obj.responseXML);
//var ado_stream = new ActiveXObject("ADODB.Stream"); 
//ado_stream.Mode=3;
//ado_stream.Type = 1;
//ado_stream.Open(); 
alert(unescape(obj.responseText));
//var db = obj.responseStream.Read();
//alert(ByteToStr(db));
//alert(obj.responseStream.Charset);

/*var tmp = escape('000000031277Ä');
alert(tmp);
alert(unescape(tmp));*/

//alert(unescape(obj.responseText));
// Pass back the object第五种方法:(我现在的解决方法)
VB组件调用js的方法escape
客户端再unescapeFunction EscapeEncode(Str As String)On Error GoTo LogError    Dim moScript
    Set moScript = CreateObject("MSScriptControl.ScriptControl")
    moScript.language = "JavaScript"
    EscapeEncode = moScript.Eval("escape('" & Str & "')")
    
LogError:
    Set moScript = Nothing
    
End Function
不过这种方法要在VB中调用js, 不是最理想的方法。 

解决方案 »

  1.   

    要使responseText能接收中文
    asp的话要在服务器端加上Response.ContentType="text/html; charset=gb2312"
      

  2.   

    obj.setRequestHeader("Content-Type", "text/html; charset=utf-8"); 
      

  3.   

    to: cloudgamer
       不是response的问题, 如果我直接用, 假如有文件test.asp如下 
        dim comObj
        set comObj = Server.CreateObject("TestCom")
       comObj.GetData()直接访问test.asp得到的瑞典字符是正常的。当通过XmlHttp去调用test.asp获取时,得到的是乱码to: tantaiyizu
        obj.setRequestHeader("Content-Type", "text/html; charset=utf-8"); 
        不起作用,而且放在open之前还报错
       
      

  4.   

    like this -var obj = new ActiveXObject("Microsoft.XMLHTTP"); 
    obj.setRequestHeader("Content-Type", "text/html; charset=utf-8");
    obj.open("GET", url, false);
    obj.send(); 执行不通过
    var obj = new ActiveXObject("Microsoft.XMLHTTP"); 
    obj.open("GET", url, false);
    obj.setRequestHeader("Content-Type", "text/html; charset=utf-8");
    obj.send(); 如果这样就OK
      

  5.   

    To: Last floor 
        Sorry, can't.var obj = new ActiveXObject("Microsoft.XMLHTTP"); 
    obj.open("GET", url, false); 
    obj.setRequestHeader("Content-Type", "text/html; charset=utf-8"); 
    obj.send(); OK是指执行通过, 但瑞典字符还是乱码