Hi there
I'm using a rest api, apparently it returns a 204 "No Content" message however my wait for statement never gets to process this.
Step 1: Get Access Token and Save it (This works perfectly!!!)
Step 2: Process some rest api calls (HERE IS THE PROBLEM)
In step 2, the endpoint is valid however returns a 204 error "no content", thing is inside b4j this is never returned at all. Any ideas on how to solve this?
I'm using a rest api, apparently it returns a 204 "No Content" message however my wait for statement never gets to process this.
Step 1: Get Access Token and Save it (This works perfectly!!!)
B4X:
'get the access token
Sub GetAccessToken() As ResumableSub
Log("GetAccessToken")
'set access token to blank
access_token = ""
Dim job As HttpJob
'initialize a http request
job.Initialize("",Me)
'pass the url to get the token
job.PostString("<endpoint>",$"grant_type=password&username=${userName}&password=${passWord}"$)
'set the content type
job.GetRequest.SetContentType("application/x-www-form-urlencoded")
'wait for the web service to complete
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
'translate to a map
Dim strResponse As String = job.GetString
job.release
Dim access As Map = Json2Map(strResponse)
'assign variables
access_token = access.GetDefault("access_token","")
'save the token to a file
File.WriteString(File.DirApp,"access_token.txt",access_token)
Return True
Else
If File.Exists(File.DirApp,accessTokenFile) Then File.Delete(File.DirApp,accessTokenFile)
LogError($"A '${job.ErrorMessage}' has been experienced reading GetAccessToken!"$)
job.Release
Return False
End If
End Sub
Step 2: Process some rest api calls (HERE IS THE PROBLEM)
B4X:
'Get Results
Sub GetResults(ID As Int) As ResumableSub
Log("GetResults")
'read the access token from file
ReadAccessToken
If access_token = "" Then Return False
'define command to read data
Dim strCommand As String = $"<EndPoint>=${ID}"$
'create an http request
Dim job As HttpJob
job.Initialize("",Me)
job.Download(strCommand)
'pass the access token
job.GetRequest.SetHeader("Authorization", "bearer " & access_token)
'wait until the job is finished
Wait For (job) JobDone(job As HttpJob)
<<<GetsStuckHere>>>
If job.Success Then
'get the response
Dim strResponse As String = job.GetString
job.release
log(strResponse)
Return True
Else
LogError($"A '${job.ErrorMessage}' has been experienced reading the GetResults!"$)
job.release
Return False
End If
End Sub
In step 2, the endpoint is valid however returns a 204 error "no content", thing is inside b4j this is never returned at all. Any ideas on how to solve this?