[Gambas-user] httpClient does not connect to a second server
John Rose
john.aaron.rose at mailbox.org
Sun Aug 30 19:10:45 CEST 2020
I am using the procedure shown below to connect to various servers,. The
variable sConnectChannelScheduleIdentifier is given a value according to
the selection of a channel. For example: BBC One HD is p00fzl6n, BBC Two
HD is p015pksy, BBC Four is p00fzl6b, BBC Four HD is p01kv81d. The
format of the server's URL is https://www.bbc.co.uk/schedules/ followed
by the identifier followed by / followed by the year followed by /w
followed by the week number (in the year) with today being the last day
in week 35. For example,
https://www.bbc.co.uk/schedules/p00fzl6n/2020/w35 is the current week's
URL for BBC One HD. Changing the URL from using w35 to w36 will give the
schedules for BBC One starting tomorrow: the BBC have already made this
server available.
First time through this procedure, it works perfectly as can be seen by
inspection of the HTMLandXML.txt file saved at the end: I've attached
the actual app's compressed source if you want to see what happens at
runtime: in fact the HTMLandXML file is horrible to look at and the data
is better inspected at by looking at a file created later called
SortedEpisodes.txt. However, when the user selects a different channel
(after the retrieval of data for the first selected channel) the same
data is retrieved and stored in the HTMLandXML.txt and
SortedEpisodes.txt files.
I've put in a hClient.Close line after the data is retrieved and stored
in the variable sBuffer but it didn't help. Is this a bug/glitch or
should I have some extra code?
Public Sub GetChannelSchedule()
' Download a file from the internet synchronously
' Put the "Async" property set to FALSE prior to Get:
' Get will then stop the program flow until all the information is
' received. In that case, you should use also the "TimeOut" property to
' set a timeout. If not, it could hang forever if the server does not
' reply properly.
Dim hClient As HttpClient
Dim sBuffer As String
hClient = New HttpClient As "hClient"
hClient.URL = "https://www.bbc.co.uk/schedules/"
hClient.URL &= sConnectChannelScheduleIdentifier
' e.g. p00fzl6n for BBC One HD, p015pksy for BBC Two HD, p00fzl6b for
BBC Four, p01kv81d for BBC Four HD
hClient.URL &= "/" & sYear & "/w" & sWeekNumber
Print "ChannelSchedule=" & hClient.URL
WriteLineToLogFile(hClient.URL)
hClient.Async = False
hClient.Timeout = 60
hClient.Encoding = "identity"
hClient.Get
If hClient.Status < 0 Then
QuitAfterError(sConnectMedium & " Channel " & sConnectChannel & "
schedule server", "not connectable to")
Else
' Success - read the data
If Lof(hClient) Then
sBuffer = Read #hClient, Lof(hClient)
Else
QuitAfterError(sConnectMedium & " Channel " & sConnectChannel & "
schedule server", "offering no programmes")
Endif
hClient.Close
If Exist(sDirectory & "/HTMLandXML.txt") Then Kill sDirectory &
"/HTMLandXML.txt"
File.Save(sDirectory & "/HTMLandXML.txt", sBuffer)
End If
End ' GetChannelSchedule
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iRecorder.tar.gz
Type: application/gzip
Size: 34097 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20200830/81c90740/attachment-0001.gz>
More information about the User
mailing list