目前我正在尝试编写一个函数来将数据发布到VBS中的IE窗口。我正在尝试修改我在VBA中编写的函数,该函数运行良好:
Sub IEPostStringRequest(URL As String, FormData As String, WebBrowser As InternetExplorer, TargetName As String)
'Send the form data To URL As POST request
Dim bFormData() As Byte
ReDim bFormData(Len(FormData) - 1)
bFormData = StrConv(FormData, vbFromUnicode)
WebBrowser.Navigate URL, 2 + 4 + 8, TargetName, bFormData, _
"Content-type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
WebBrowser.Navigate
End Sub
您向它发送一个URL,将查询字符串作为FormData,一个已经存在的InternetExplorer对象,以及一个目标帧,并将该请求发送到该帧。但是,StrConv在VBS中不起作用,我找不到合适的替代品。似乎必须有更好的方法,因为发送帖子请求相当简单。我该怎么办?
答案 0 :(得分:0)
尝试使用ADODB.Stream
ActiveX将字符串转换为二进制字节数组:
With CreateObject("ADODB.Stream")
.Open
.Type = 2 ' adTypeText
.Charset = "us-ascii"
.WriteText FormData
.Position = 0
.Type = 1 ' adTypeBinary
bFormData = .Read
.Close
End With