Getting Input from an HTTPS Link using VB6
I'm trying to get a simple random number from this site using the code as shown there, for example this:
https://qrng.anu.edu.au/API/jsonI.ph...=5&type=uint16
will return a number from 0-65535. It works on the website itself but what kind of code should I use in VB6 to "send" such a link to the website and "receive" the number returned properly? Are there any special libraries in VB6 that also need to be imported? Thanks.
Re: Getting Input from an HTTPS Link using VB6
when i use the link posted, in internet explorer, it asks to open or save
firefox just opens the data in the browser, but unfortunately this does not help us
here is some basic code to post the query
Code:
Set wb = CreateObject("internetexplorer.application")
wb.Visible = True 'optional, but good while testing
wb.navigate2 "https://qrng.anu.edu.au/API/jsonI.php?length=5&type=uint16"
but to read the data back is more difficult as the open save dialog presented does not contain the data
if you click save the data can be read from the saved file, but would probably require the use of APIs to click the save button and pass a file name to save to
Re: Getting Input from an HTTPS Link using VB6
Yeah, that doesn't seem to be working too well. I thought the solution might look something like this, but less complicated and with fewer dependencies. Right now I'd even settle for an executable I can just pass the HTTPS link to and read the output somehow.
Re: Getting Input from an HTTPS Link using VB6
Quote:
Originally Posted by
victor_knight
Are there any special libraries in VB6 that also need to be imported?
No need to import anything. Try this snippet in a new Std-EXE project
Code:
Option Explicit
Private Sub Form_Load()
With InitRequest("GET", "https://qrng.anu.edu.au/API/jsonI.php?length=5&type=uint16", Async:=False)
.Send
Debug.Print .ResponseText
End With
End Sub
Private Function InitRequest(sType As String, sUrl As String, Optional ByVal Timeout As Single, Optional ByVal Async As Boolean, Optional RetVal As Object) As Object
Dim lMili As Long
'--- first try server-side XMLHTTP because it has timeouts
If Timeout <> 30 Then
Set RetVal = CreateObject("MSXML2.ServerXMLHTTP")
End If
If Not RetVal Is Nothing Then
lMili = Switch(Timeout < 0, 0, Timeout > 0, Timeout, True, 30) * 1000
RetVal.SetTimeouts 5000, 5000, lMili, lMili
Else
Set RetVal = CreateObject("MSXML2.XMLHTTP")
End If
RetVal.Open sType, sUrl, Async
Set InitRequest = RetVal
End Function
Let me know if you need a JSON parser for the contents in ResponseText or you can use it as is.
cheers,
</wqw>
Re: Getting Input from an HTTPS Link using VB6
This looks very promising, thanks. I'll give it some testing.
Re: Getting Input from an HTTPS Link using VB6
much better than my partial attempt