B4X:
'Handler class
Sub Class_Globals
End Sub
Public Sub Initialize
End Sub
Sub Handle(req As ServletRequest, resp As ServletResponse)
Try
request1
StartMessageLoop
'Do the work according to the results of request 1
If XXXXXX Then
request2
StartMessageLoop
Else
request3
StartMessageLoop
End If
Catch
resp.SendError(500, "error....")
End Try
End Sub
Sub request1()
Dim hp As HttpJob
hp.Initialize("",Me)
hp.Download("http://www.example.com")
Wait For(hp)JobDone(hp As HttpJob)
'I need to return the result here
hp.Release
StopMessageLoop
End Sub
Sub request2()
Dim hp As HttpJob
hp.Initialize("",Me)
hp.Download("http://www.example.com")
Wait For(hp)JobDone(hp As HttpJob)
'I need to return the result here
hp.Release
StopMessageLoop
End Sub
Sub request3()
Dim hp As HttpJob
hp.Initialize("",Me)
hp.PostString("http://www.example.com",data)
hp.GetRequest.SetHeader("Content-Type","application/json")
hp.GetRequest.SetHeader("Content-Length",data.Length)
Wait For(hp)JobDone(hp As HttpJob)
'I need to return the result here
hp.Release
StopMessageLoop
End Sub
The code structure looks something like the above. (1) I want to return a value, what can I do? (2)request3's request will have status code 204 and a blank response. The expectation is that the other server will log my submitted data and generate a transaction entry. But it did not. My POSTMAN works fine.This problem has been bothering me for two days, and I don't know what I did wrong.
Last edited: