下面是一个webbrowser直接向远程服务器提交post请求的代码,但是在碰到ascII(0-255)码范围外的特殊字符的时候例如△时,asc()返回一个负数,post未能成功提交△,后改用ascw()函数,结果返回9651,但抓包发现,post出去的数据还是变成"."号了,请问大家如何解决这个问题,要求用webbrowser解决,分数不够再加,谢谢!Private Sub Form_Load()    Timer2.Interval = 30000
    
    ReDim aByte(0) As Byte
    
    Dim vPost As Variant
    
    Dim vHeaders As Variant
    
    vHeaders = "Content-Type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
    
    cPostData = "id=111&ps=222"    PackBytes aByte(), cPostData    vPost = aByte
    
    WebBrowser1.Navigate "http://domain.com/test.cgi", , , vPost, vHeaders
End Sub
Private Sub PackBytes(ByteArray() As Byte, ByVal PostData As String)      iNewBytes = Len(PostData) - 1   ' Get rid of the null termination      If iNewBytes < 0 Then       Exit Sub      End If      ReDim ByteArray(iNewBytes)      For i = 0 To iNewBytes       ch = Mid(PostData, i + 1, 1)       If ch = Space(1) Then          ch = "+"       End If       Debug.Print ch, Asc(ch)       ByteArray(i) = Asc(ch)      Next      
End Sub

解决方案 »

  1.   

    URL在提交的时候要做个URL编码的.就是在地址栏里经常见到的%符号的由来.
      

  2.   

    在 VB自动登陆网络站点详解(三):Internet Explorer对象的评论里面   griefforyou网友已经修改过了:
    提交的信息里有汉字的话不能直接用asc来转换,我改了一下PackBytes函数:
    Private Sub PackBytes(ByteArray() As Byte, ByVal PostData As String)
    Dim iNewBytes As Integer
    Dim i As Integer, j As Integer, ch As String
    Dim strHex As String    iNewBytes = LenB(StrConv(PostData, vbFromUnicode)) - 1
        If iNewBytes < 0 Then Exit Sub
        
        ReDim ByteArray(iNewBytes) As Byte
        For i = 0 To Len(PostData) - 1
            ch = Mid(PostData, i + 1, 1)
            If ch = "" Then
                ch = "+"
                ByteArray(j) = Asc(ch)
            ElseIf Asc(ch) < 0 Then
                ByteArray(j) = CByte("&H" & Left(Hex(Asc(ch)), 2))
                j = j + 1
                ByteArray(j) = CByte("&H" & Right(Hex(Asc(ch)), 2))
            Else
                ByteArray(j) = Asc(ch)
            End If
            j = j + 1
        Next
    End Sub