在用inet往一个utf-8网站提交数据的时候
我发现一个问题,就是,当我提交的内容是字母和数字的时候,一切都是正常的。
如果我只提交带汉字的就会出现下列情况:title=StrConv(UnicodeToUtf8("中华人民共和国"), vbUnicode)这样,提交上去标题就是  中华人民共和用别的方法提交的话不是乱码就是空。请问这个问题该如何解决?麻烦给个代码。谢谢了。

解决方案 »

  1.   

    应该是你UnicodeToUtf8转的时候字节数少了
      

  2.   

    这是我这里的:Function UnicodeToUtf8(ByVal UCS As String) As Byte()
        Dim lLength As Long
        Dim lBufferSize As Long
        Dim lResult As Long
        Dim abUTF8() As Byte
        lLength = Len(UCS)
        If lLength = 0 Then Exit Function
        lBufferSize = lLength * 3 + 1
        ReDim abUTF8(lBufferSize - 1)
        lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(UCS), lLength, abUTF8(0), lBufferSize, vbNullString, 0)
        If lResult <> 0 Then
        lResult = lResult - 1
        ReDim Preserve abUTF8(lResult)
        UnicodeToUtf8 = abUTF8
        End If
    End Function
      

  3.   

    试试这个
    Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
    Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
    '常用的代码页:
    const cpUTF8   =65001
    const cpGB2312 =  936
    const cpGB18030=54936
    const cpUTF7   =65000
    Function MultiByteToUTF16(UTF8() As Byte, CodePage As Long) As String
        Dim bufSize As Long
        bufSize = MultiByteToWideChar(CodePage, 0&, UTF8(0), UBound(UTF8) + 1, 0, 0)
        MultiByteToUTF16 = Space(bufSize)
        MultiByteToWideChar CodePage, 0&, UTF8(0), UBound(UTF8) + 1, StrPtr(MultiByteToUTF16), bufSize
    End FunctionFunction UTF16ToMultiByte(UTF16 As String, CodePage As Long) As Byte()
        Dim bufSize As Long
        Dim arr() As Byte
        bufSize = WideCharToMultiByte(CodePage, 0&, StrPtr(UTF16), Len(UTF16), 0, 0, 0, 0)
        ReDim arr(bufSize - 1)
        WideCharToMultiByte CodePage, 0&, StrPtr(UTF16), Len(UTF16), arr(0), bufSize, 0, 0
        UTF16ToMultiByte = arr
    End FunctionPrivate Sub Command1_Click()
        MsgBox MultiByteToUTF16(UTF16ToMultiByte("ab中,c", cpUTF8), cpUTF8)
    End Sub