My question is on lesson 6 where you show the alternatives to the webbrowser control. I find it cool. I would like you; 1. To demonstrate how to use the post method using any of these two ways shown in the lesson. Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") 'Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
2. I came across another way to go to a web page using VBA without the web browser control. I paste it below; Public Function HTTPPost(URL As String, Msg As String) 'send HTTP POST to a server: With CreateObject("WinHttp.WinHttpRequest.5.1") On Error Resume Next 'ensures code contiunes to run without internet .Open "GET", URL, True 'True is asynchronous so UI does not hang .setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" .setRequestHeader "Content-type", "application/x-www-form-urlencoded" '.SetRequestHeader "secret-pass-key", "your-key" <--if needed .send Msg 'throws an error when there is no internet .WaitForResponse 'pauses execution, but does not hang UI
HTTPPost = .responseText
End With End Function
Now i am in a dilemma. Which of the three options should i use? Which one is future proof? Which one is better?
XMLHTTP and WinHttpRequest are very similar. That's really just a matter of preference. I've been using XMLHTTP for years with no issues. Both are definitely superior to the webbrowser control - unless your goal is to display something in a web browser for the user.