添加完成後,添加以下代碼即可完成POST數據發送
Option Explicit
Dim xml As XMLHTTP60
Private Sub Command1_Click()
xml.open "POST", "/", True '註明是POST請求,當然也可以get
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim str As String
str = str & "wd=關鍵" '可以在這裏添加參數
str = p_URLEncoding(str) '需要將POST的數據進行編碼
xml.send str
End Sub
Private Sub Form_Load()
Set xml = New XMLHTTP60
End Sub
'編碼函數
Private Function p_URLEncoding(vstrIn) As String
'/////////////////////////////////////////////////
'解決編碼轉換問題 POST GB2312 編輯的數據
Dim i As Long
Dim strReturn As String
Dim ThisChr As String
Dim innerCode As Long
Dim Hight8 As Long
Dim Low8 As Long
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vstrIn, i, 1)
If Abs(Asc(ThisChr)) < &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
p_URLEncoding = strReturn
End Function