Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Is there any way to send web request and get answer via VBA?
Regards,
Mucip:)
Solved! Go to Solution.
Hi,
Is there any way to send web request and get answer via VBA?
Regards,
Mucip:)
Solved! Go to Solution.
There is no direct support inside VBA to send/receive http request/response. You would have to use MSXML (6.0 is the latest/last version?). It is an old, obsolete technology by now.
You might be able to find third party COM-based http(s) components, such as these:
https://www.chilkatsoft.com/HttpActiveX.asp
https://www.weonlydo.com/HttpDLX/http-web-component.asp
However, if the business solution involves http(s) access, I would not waste time (and money on third party software) on VBA, if I were you. It can be easily done with MS .NET, now that AutoCAD .NET API is the main stream of AutoCAD programming.
Dear @norman.yuan ,
Thanks a lot.
Yes, you always suggesting me to jump in to C# 🙂
But I really prefer C++ and don't like C#. By the way my goal is almost finished. I don't want to waste time again my VBA project to C# conversion.
In any way. Thanks again.
And If I need to write something in AutoCAD next time than I will start with C# I promiss 🙂
Regards,
Mucip:)
Dear @norman.yuan ,
I solved below code with your guidence.
Public Function GetServerOK() As String
Dim HttpRequest As Object
Dim data
On Error Resume Next
'Create the XMLHttpRequest object.
Set HttpRequest = CreateObject("MSXML2.XMLHTTP")
'Check if the object was created.
If Err.Number <> 0 Then
'Return error message.
GetServerOK= "Could not create the XMLHttpRequest object!"
'Release the object and exit.
Set HttpRequest = Nothing
Exit Function
End If
On Error GoTo 0
'Create the request - no special parameters required.
HttpRequest.Open "POST", "http://XX.YY/met/server.php", False
HttpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
data = "info=" & GetMyLine()
HttpRequest.send data
'Return the result of the request (the IP string).
GetServerOK= HttpRequest.responseText
End Function
I created simple php file on Debian/Apache and send back echo according to POST value.
Source: https://www.codegrepper.com/code-examples/vb/vba+send+post+request+MSXML2.XMLHTTP
Regards,
Mucip:)
Hi again,
For Win7, you need to use below line:
'For Win10
Set HttpRequest = CreateObject("MSXML2.XMLHTTP")
'For Win7 & working Win10 also
Set HttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
Regards,
Mucip:)