Hi all.
I need to make a GET request through a handler and display the result on the screen.
I tried to follow @Erel tutorial on how to use wait on a handler but I was not successful.
here's the code.
if I use the code above (uncommented) I have the following error:
and if I remove StartMessageLoop and StopMessageLoop I sometimes get the duplicate answer.
the code log above is
what would be the correct way to use wait, wait for his answer and not duplicate the answer on the screen for the user?
should I use StartMessageLoop and StopMessageLoop?
if so, where should i use exactly?
thanks
I need to make a GET request through a handler and display the result on the screen.
I tried to follow @Erel tutorial on how to use wait on a handler but I was not successful.
here's the code.
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
Wait For (Check_Ip(req.RemoteAddress)) Complete (origem As String)
resp.Write(origem)
resp.Write("test1")
'StartMessageLoop '<< HERE?
End Sub
Sub Check_Ip(ip As String) As ResumableSub
Private origem As String = "N/A"
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://ip.com/ip/" & ip)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
If j.GetString.Contains("origem") Then
Dim parser As JSONParser
parser.Initialize(j.GetString)
origem = parser.NextObject.Get("origem")
End If
End If
j.Release
'StopMessageLoop HERE?
Return origem.ToUpperCase
End Sub
if I use the code above (uncommented) I have the following error:
Program terminated (StartMessageLoop was not called).
and if I remove StartMessageLoop and StopMessageLoop I sometimes get the duplicate answer.
the code log above is
N/Atest1N/Atest1
what would be the correct way to use wait, wait for his answer and not duplicate the answer on the screen for the user?
should I use StartMessageLoop and StopMessageLoop?
if so, where should i use exactly?
thanks