PostRequest "http://127.0.0.21/faccept.asp", _
Array("FirstName", "LastName", "Email"), _
Array("Franta", "Vomacka", "fanda@mobula.com")
'**************************************** Post form data - begin
'sends form fields specified In Names/Values arrays To the URL
Sub PostRequest(URL, Names, Values)
Dim I, FormData, Name, Value
'Enumerate form names And it's values
'and built string representaion of the form data
For I = 0 To UBound(Names)
'URL encode source fields
Name = URLEncode(Names(I))
Value = URLEncode(Values(I))
If FormData <> "" Then FormData = FormData & "&"
FormData = FormData & Name & "=" & Value
Next
IEPostStringRequest URL, FormData
End Sub
'sends URL encoded form data To the URL using IE
Sub IEPostStringRequest(URL, FormData)
'Create InternetExplorer
Dim WebBrowser: Set WebBrowser = CreateObject("InternetExplorer.Application")
'You can uncoment Next line To see form results As HTML
'WebBrowser.Visible = True
'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, , bFormData, _
"Content-type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
Do While WebBrowser.busy
' Sleep 100
DoEvents
Loop
WebBrowser.Quit
End Sub
'URL encode of a string data
Function URLEncode(Data)
Dim I, C, Out
For I = 1 To Len(Data)
C = Asc(Mid(Data, I, 1))
If C = 32 Then
Out = Out + "+"
ElseIf C < 48 Then
Out = Out + "%" + Hex(C)
Else
Out = Out + Mid(Data, I, 1)
End If
Next
URLEncode = Out
End Function
'**************************************** Post form data - end
|