Hi Experts,
I am back with another interesting pop quiz, which I am sure an expert can solve in 5 seconds!
You see I am trying to get a string (The Server just answers back 'Hello World!') from a Response_Success event like this:
Now I get no errors, but my DataBytes & strTemp variables are blank.
The os buffer is full of data though, that I can see.
But If I go one step further and write the Response to a text file and then use:
Then I will see my 'Hello World' in strTemp.
What am I am doing wrong?
Regards,
Jacques.
I am back with another interesting pop quiz, which I am sure an expert can solve in 5 seconds!
You see I am trying to get a string (The Server just answers back 'Hello World!') from a Response_Success event like this:
B4X:
Private Sub HTTPClient_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
Dim os As OutputStream
os.InitializeToBytesArray(100)
'Write response as a text file.
'This will work, but trying to avoid this extra step.
'Response.GetAsynchronously("Response",File.OpenOutput(File.DirInternalCache,"Response.txt",False),True,TaskId)
Response.GetAsynchronously("Response",os,True,TaskId)
Dim DataBytes() As Byte = os.ToBytesArray
Dim strTemp As String = BytesToString(DataBytes,0,DataBytes.Length,"UTF8")
End Sub
Now I get no errors, but my DataBytes & strTemp variables are blank.
The os buffer is full of data though, that I can see.
But If I go one step further and write the Response to a text file and then use:
B4X:
Private Sub Response_StreamFinish(Success As Boolean,TaskID As Int)
Dim strTemp As String = File.ReadString(File.DirInternalCache, "Response.txt")
End Sub
Then I will see my 'Hello World' in strTemp.
What am I am doing wrong?
Regards,
Jacques.