例子如下:
                XMLHTTP myxml=new XMLHTTP();
myxml.open("POST","http://aa/myabc/aa.asp",false,"","");
string str="login=aaa;pass=bbb";
myxml.setRequestHeader("content-length",str.Length.ToString());
myxml.setRequestHeader("content-type","application/x-www-form-urlencoded");
myxml.send(str);
Response.write(myxml.ResponseText)
的内容是乱码,其实在ASP里也有出现类似的问题,但是用了一个函数:
Function GetBytes2BSTR(p_sHtmlStr)
dim sReturnStr
dim i,n    sReturnStr = ""
n = LenB(p_sHtmlStr)    For i = 1 To n
dim sCharCode
dim sNextCharCode        sCharCode = AscB( MidB(p_sHtmlStr, i, 1) )        If (sCharCode < &H80) Then
            sReturnStr = sReturnStr & Chr(sCharCode)
        Else
            sNextCharCode = AscB( MidB(p_sHtmlStr, i+1, 1) )
            sReturnStr = sReturnStr & Chr(CLng(sCharCode) * &H100 + CInt(sNextCharCode))
            i = i + 1
        End If
    Next    GetBytes2BSTR = sReturnStr
End Function
将其进行转换,使之变正常的文字,但在C#里就不知怎么转换了

解决方案 »

  1.   

    解决之道
    客户端解码:
    var u64='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
    var f1=u64.substr(0,16);
    var f2=u64.substr(16,16);
    var f3=u64.substr(32,16);
    function LostinetEncode(str)
    {
    var res='';
    var len=str.length;
    for(var i=0;i<len;i++)
    {
    var cc=str.charCodeAt(i);
    if(cc<256)
    {
    if(i+1<len)
    {
    var ccnext=str.charCodeAt(i+1);
    if(ccnext<256)
    {
    i++;
    cc+=ccnext*256;
    res+=f3.charAt(cc%16)+u64.charAt((cc>>4)%64)+u64.charAt((cc>>10)%64);
    continue;
    }
    }
    res+=f2.charAt(cc%16)+f2.charAt(cc>>4);
    }
    else
    {
    res+=f1.charAt(cc%16)+u64.charAt((cc>>4)%64)+u64.charAt((cc>>10)%64);
    }
    }
    return res;
    }
    服务器端解码:
    static string u64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    static string f1="ABCDEFGHIJKLMNOP";
    static string f2="QRSTUVWXYZabcdef";
    static string f3="ghijklmnopqrstuv";
    static string LostinetDecode(string str)
    {
    if(str==null) return "";
    StringBuilder sb=new StringBuilder();
    int len=str.Length;
    int cc1,cc2,cc3;
    for(int i=0;i<len;i++)
    {
    char fc=str[i];
    cc1=f1.IndexOf(fc);
    if(cc1>-1)
    {
    cc2=u64.IndexOf(str[++i]);
    cc3=u64.IndexOf(str[++i]);
    sb.Append( (char)(cc1+cc2*16+cc3*1024) );
    }
    else
    {
    cc1=f2.IndexOf(fc);
    if(cc1>-1)
    {
    cc2=f2.IndexOf(str[++i]);
    sb.Append( (char)(cc1+cc2*16) );
    }
    else
    {
    cc1=f3.IndexOf(fc);
    cc2=u64.IndexOf(str[++i]);
    cc3=u64.IndexOf(str[++i]);
    int ccx=cc1+cc2*16+cc3*1024;
    sb.Append( (char)(ccx%256) );
    sb.Append( (char)(ccx>>8) );
    }
    }
    }
    return sb.ToString();
    }再详细点,请参考Lostinet兄的Janc
      

  2.   

    谢谢几位了,我决定不用xmlhttp来获取数据了。但HttpWebRequest可以实现的,马上散分