I'm trying to post data using the wininet.dll, and the data isn't posting.
I'm sending the request, and recieving the response, but the data isn't posting correctly. Here's the code I have...
(W32 Constants and Function Aliases snipped for brevity)
I know my test.php works, because works as expected.
Any help on this would be REALLY appreciated.
Thanks in advance -
leo
I'm sending the request, and recieving the response, but the data isn't posting correctly. Here's the code I have...
(W32 Constants and Function Aliases snipped for brevity)
Code:
Private Const HttpPost_Header = "Content-Type: application/x-[URL unfurl="true"]www-form-urlencoded"[/URL] & vbCrLf
Function sendData(fn As String)
Dim hInternet As Long, hConnect As Long, lFlags As Long, hRequest As Long
Dim bRes As Boolean
Dim strPostData As String 'holds all the post information
strPostData = "table=some table&csv=blah,blah" & vbCrLf & "other stuff"
lFlags = INTERNET_FLAG_NO_COOKIES
lFlags = lFlags Or INTERNET_FLAG_NO_CACHE_WRITE
'Initiate the 'socket'
hInternet = 0
hInternet = InternetOpen("title", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
If hInternet = 0 Then 'error check
MsgBox "Verify you're connected to the Internet, then try exporting again"
Exit Function
End If
'Establish the connection
hConnect = InternetConnect(hInternet, "[URL unfurl="true"]www.cherryone.com",[/URL] "80", "", "", INTERNET_SERVICE_HTTP, 0, 0)
If hConnect = 0 Then
MsgBox "Could not connect to cherryone.com!"
Exit Function
End If
'Open object for posting
hRequest = HttpOpenRequest(hConnect, "POST", "playground/test.php", "HTTP/1.0", vbNullString, vbNullString, lFlags, 0)
If hRequest = 0 Then
InternetCloseHandle hRequest
MsgBox "Could not establish engine connection"
Exit Function
End If
'Add request headers, so the formdata is processed correctly
Call HttpAddRequestHeaders(hRequest, HttpPost_Headers, Len(HttpPost_Header), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)
'Send the request (yes, I've never done this before, thus the excessive comments)
bRes = HttpSendRequest(hRequest, vbNullString, 0, strPostData, Len(strPostData))
If bRes = False Then
InternetCloseHandle (hRequest)
InternetCloseHandle (hInternet)
MsgBox "HTTP Request Not posted successfully!"
Exit Function
End If
Dim strBuffer As String * 2048
Dim lBytesRead As Long
Dim str As String
Do
bRes = InternetReadFile(hRequest, strBuffer, Len(strBuffer), lBytesRead)
If lBytesRead > 0 Then
str = str & strBuffer
End If
Loop While lBytesRead > 0
MsgBox str
'Clean up the connections
InternetCloseHandle (hRequest)
InternetCloseHandle (hInternet)
End Function
I know my test.php works, because works as expected.
Any help on this would be REALLY appreciated.
Thanks in advance -
leo