NavigatePost

Reads content of webpage with optional post data
two main differences from Navigate, this one uses another library (WinHttpRequest vs MSXML2) and method 'Post' vs 'Get'
Library should already be selected as part of project (see screenshot)

CodeFunctionName
What is this?

Public

Tested

Original Work
Public Function NavigatePost(sURL As String, sPostData As String) As String
    Dim HttpReq As WinHttpRequest
    Set HttpReq = New WinHttpRequest
'    Dim HttpReq As MSXML2.XMLHTTP60, Errcount
'    Set HttpReq = New MSXML2.XMLHTTP60
    On Error Resume Next
    HttpReq.Open "POST", sURL, False    ' toggle the use of these lines if did not work
    HttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'    HttpReq.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
'    HttpReq.Open "GET", sURL, True
    DoEvents
    HttpReq.send sPostData
    HttpReq.waitForResponse
Do1:
    DoEvents
    NavigatePost = HttpReq.responseText
    DoEvents
    If HttpReq.Status = 200 Then
        NavigatePost = HttpReq.responseText
        DoEvents
    Else
        DoEvents
        GoTo Do1
    End If
    GoTo ByeBye
Err11:
    'Errcount = Errcount + 1
    'If Errcount > 10 Then GoTo ByeBye
    'Set HttpReq = Nothing
    'DoEvents
    'Err.Clear
    'ReadSStatus
    GoTo ByeBye
ByeBye:
    Set HttpReq = Nothing
End Function

sURL As String, sPostData As String

Views 99

Downloads 24

CodeID
DB ID