能不能基于webBrowser的基础上发送post请求
1个回答
展开全部
新建一个工程,部件中勾选中“Microsoft Internet Controls”,添加一个WebBrowser1、一个Command1在窗体上,可以把WebBrowser1适当拉大一点,Form1中添加以下代码:
Private Sub Command1_Click()
ReDim aByte(0) As Byte ' Array of bytes to hold data to post
cPostData = "login_name=帐号&password=密码&cookietime=0&x=42&y=10"
PackBytes aByte(), cPostData
Dim vPost As Variant
vPost = aByte ' Assign the byte array to a VARIANT
Dim vHeaders As Variant
vHeaders = "Content-Type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
WebBrowser1.Navigate "http://www.csdn.net/member/logon.asp", , , 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
Private Sub Command1_Click()
ReDim aByte(0) As Byte ' Array of bytes to hold data to post
cPostData = "login_name=帐号&password=密码&cookietime=0&x=42&y=10"
PackBytes aByte(), cPostData
Dim vPost As Variant
vPost = aByte ' Assign the byte array to a VARIANT
Dim vHeaders As Variant
vHeaders = "Content-Type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
WebBrowser1.Navigate "http://www.csdn.net/member/logon.asp", , , 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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询