1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| '****************************************
'Post form data - begin
'sends form fields specified In Names/Values arrays To the URL
Sub PostRequest(strURL As String, aNames, aValues)
Dim i As Integer
Dim strFormData As String
Dim strName As String
Dim strValue As String
'Enumerate form names And it's values
'and built string representaion of the form data
For i = 0 To UBound(aNames)
'URL encode source fields
strName = URLEncode(aNames(i))
strValue = URLEncode(aValues(i))
If strFormData <> "" Then strFormData = strFormData & "&"
strFormData = strFormData & strName & "=" & strValue
Next
IEPostStringRequest strURL, strFormData
End Sub
'sends URL encoded form data To the URL using IE
Sub IEPostStringRequest(URL, FormData)
'Send the form data To URL As POST request
Dim bFormData() As Byte
ReDim bFormData(Len(FormData) - 1)
bFormData = StrConv(FormData, vbFromUnicode)
objIE.navigate URL, 2 + 4 + 8, , bFormData, _
"Content-type: application/x-www-form-urlencoded" + Chr(10) + Chr(13)
Do Until objIE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
End Sub
'URL encode of a string data
Function URLEncode(strData)
Dim i As Long
Dim C As Integer
Dim strOut As String
For i = 1 To Len(strData)
C = Asc(Mid(strData, i, 1))
Select Case C
Case 32
strOut = strOut + "+"
Case 0 To 31, 33 To 47, 58 To 64, 91 To 94, 96, 123 To 127
strOut = strOut + "%" + Hex(C)
Case Else
strOut = strOut + Mid(strData, i, 1)
End Select
Next
URLEncode = strOut
End Function
'Post form data - end
'**************************************** |
Partager