XMLHTTP Chinese Gbk,uft-8 garbled resolution method

Source: Internet
Author: User
Tags chr html form

Recently used DHTMLX tree, Chinese XML can not use, error, the whole system is gb2312, and DHTMLX only support UTF8, English is normal, Chinese error.

The discovery is, microsoft.xmlhttp the reason, has found the above file.

<script language= "VBScript" >
' Handling Chinese
function Bin2str (BIN)
Dim tmp,ustr,i
Tmp= ""
For I=1 to LenB (bin)-1
USTR=ASCB (MidB (bin,i,1))
If ustr>127 Then
I=i+1
TMP=TMP&CHR (USTR*256+ASCB (MidB (bin,i,1))
Else
TMP=TMP&CHR (USTR)
End If
Next
Bin2str=tmp
End Function
</script>

Here is a detailed example

<script language= "Web Effects" >
Stra = "SUBMIT1=SUBMIT&TEXT1=SCSDFSD";
var oreq = new ActiveXObject ("Msxml2.xmlhttp");
Oreq.open ("Post", "Http://servername/vdir/tstresult.asp Tutorial", false);
Oreq.setrequestheader ("Content-length", stra.length);
Oreq.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Oreq.send (Stra);
</script>

If the Stra = "SUBMIT1=SUBMIT&TEXT1=SCSDFSD", replace it with:
Stra = "submit1=submit&text1= Chinese";
You will find that the things submitted to the wrong, ASP Request.Form ("Text1") can not get the value. I use Request.BinaryRead to write a post in an HTML form to look at, only to find the problem--form submitted to the code, after the encoding of Chinese is similar to%?? %?? Escape characters, such as "Chinese", are encoded as:%D6%D0%CE%C4. Oh, also blame me stupid, someone else content-type clearly write clearly--application/x-www-form-urlencoded,urlencoded well, of course it is this appearance. In that case, we also know what to do--do the conversion ourselves

<script language= "VBScript" >
function urlencoding (Vstrin)
Strreturn = ""
For i = 1 to Len (Vstrin)
THISCHR = Mid (vstrin,i,1)
If ABS (ASC (THISCHR)) < &AMP;HFF Then
Strreturn = Strreturn & THISCHR
Else
Innercode = ASC (THISCHR)
If Innercode < 0 Then
Innercode = Innercode + &h10000
End If
Hight8 = (Innercode and &hff00) &hff
Low8 = Innercode and &hff
Strreturn = strreturn & "%" & Hex (HIGHT8) & "%" & Hex (LOW8)
End If
Next
urlencoding = Strreturn
End Function
Stra = urlencoding ("submit1=submit&text1= Chinese")
Oreq = CreateObject ("Msxml2.xmlhttp")
Oreq.open "Post", "http://servername/vdir/tstresult.asp", False
Oreq.setrequestheader "Content-length", Len (stra)
Oreq.setrequestheader "Content-type", "application/x-www-form-urlencoded"
Oreq.send Stra
</script>
Garbled mainly in Chinese, because the XMLHTTP default send code is UFT-8 so if you want to process Chinese URL code on the line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.