A urgent problem caused by Msxml2.XMLHTTP RRS feed

  • Question

  • User1926312563 posted


    everyone , I use Msxml2.XMLHTTP to access some web page which filled with Chinese character(GB2312),while the result is some stranger code,like this


    someone say when access these web page,the return result is coded by utf-8,but how I change them into GB2312, or how can I do ,the result is changed into GB2312 automatically.

    thank you.!

    Sunday, June 11, 2006 2:38 AM

All replies

  • User-1422796318 posted

    Please use the following code to have a quick test:

    Dim myhttp
    Set myhttp=CreateObject("Msxml2.XMLHTTP.4.0")
    myhttp.open "GET", "http://youriisserver/test1.asp", false
    myhttp.SetRequestHeader "Content-Type", "text/xml"
    myhttp.SetRequestHeader "charset", "gb2312"
    msgbox myhttp.responsetext

    Monday, June 12, 2006 4:49 AM
  • User1926312563 posted

    thank you YongKang.

    After I search on the net and get to know that when XMLHTTP sents a reqeust,the response is coded in UTF-8 automatically, so the result we cann't process directly until it is recoded. some methods are presented on the net and I pick up a efficient way .It like these:

    Function ByteToText(body,Cset)
    dim objstream
    set objstream = Server.CreateObject("adodb.stream")
    objstream.Type = 1
    objstream.Mode =3
    objstream.Write body
    objstream.Position = 0
    objstream.Type = 2
    objstream.Charset = Cset
    ByteToText = objstream.ReadText
    set objstream = nothing
    End Function

    The function was coded in vbscript. the first parameter is a string of binary data. the second is the format which you want to recode. so I only pass two parameter to the function then I can get what I want.

    str = ByteToText(xmlHttp.responseBody,"GB2312")


    Wednesday, June 14, 2006 3:42 AM