-
May 16th, 2020, 08:46 PM
#1
Thread Starter
Junior Member
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.
-
May 18th, 2020, 07:20 AM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 18th, 2020, 07:39 AM
#3
Thread Starter
Junior Member
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.
-
May 18th, 2020, 09:28 AM
#4
Re: Getting Input from an HTTPS Link using VB6
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>
-
May 18th, 2020, 09:40 AM
#5
Thread Starter
Junior Member
Re: Getting Input from an HTTPS Link using VB6
This looks very promising, thanks. I'll give it some testing.
-
May 19th, 2020, 05:11 AM
#6
Re: Getting Input from an HTTPS Link using VB6
much better than my partial attempt
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|