I declare a string spage, a HHTPClient and a HTTPRequest in the Globals sub. In an OnClick sub I get a global request object and make a HTTP request. On success I assign the results of the request to the string spage and show a fragment of it in a msgbox. Then I call a sub which tests the length of spage and behold! it is zero.
What am I doing wrong, please?
What am I doing wrong, please?
B4X:
Sub Button1_Click
ProgressDialogShow("Loading data from www")
URL = "http://www.bbc.co.uk"
request.InitializeGet(URL)
request.Timeout = 10000 'set timeout to 10 seconds
If HttpClient1.Execute(request, 300) = False Then Msgbox("error","err")
End Sub
Sub Http_ResponseSuccess (Response As HttpResponse, TaskId As Int)
ProgressDialogHide
spage = (Response.GetString("UTF8"))
Msgbox(spage.SubString2(1, 100),"results") '<----- results shown
scrape
End Sub
Sub scrape
dim l as int
l = spage.length()
If l = 0 Then
Msgbox("no data from HTTP GET","error") '<----- error shown
Return
End If
End Sub