Probably the answer is very simple but i can't read data from an httpjob when the results contains special char as ò à è ù ecc.
Sure is a decode problem but i can't find right syntax for solve my problem
thia is my code
B4X:
Dim j As HttpJob
j.Initialize("j", Me)
j.Download("https://mysever.est/filmtitlelist.php")
Wait For (j) JobDone(j As HttpJob)
File.WriteString(File.DirDocuments,"localfile.txt",j.GetString)
web server returns a list of movie titles like this
HTML:
001 La vita è bella
002 Roma città aperta
003 La dolce vita
004 Paisà
005 Sciuscià
Anda httpjob reports this error
Error occurred on line: xxx (HttpJob)
Error decoding data as string.
This is a slightly modified sub based on the code from: [B4X] OkHttpUtils2 with Wait For Call it when you want to download a file and save it. You can wait for it to complete if needed. Sub DownloadAndSave (Url As String, Dir As String, FileName As String) As ResumableSub Dim j As HttpJob...
Accelerate API development with Postman's all-in-one platform. Streamline collaboration and simplify the API lifecycle for faster, better results. Learn more.
Now i can solve it simply by editing the php file on the server and convert all accented char or create a little function in B4i for filtering web result, but i'll like to understand better difference from B4A and B4i then often are quite important
in B4A i use a TextReader for read downloaded result
B4X:
Dim j As HttpJob
j.Initialize("j", Me)
j.Download("https://myserver.est/filmtitlelist.php)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "localfile.txt", False)
File.Copy2(job.GetInputStream, out)
out.Close
End If
j.release
Dim reader As TextReader
reader.Initialize(File.OpenInput(File.DirInternal, "localfile.txt"))
line = reader.ReadLine
in B4i i have to use a List (if is correct)
B4X:
Dim mylist As list
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://myserver.est/filmtitlelist.php")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirDocuments, "localfile.txt", False)
File.Copy2(j.GetInputStream, out)
out.Close
End If
j.Release
mylist=File.ReadList(File.DirDocuments,"localfile.txt")
code is very similar: where is the problem of decoding? in j.download of B4i vs j.download of B4A or in list vs textreader (or in my mind) ?
Accelerate API development with Postman's all-in-one platform. Streamline collaboration and simplify the API lifecycle for faster, better results. Learn more.
j.Initialize("", Me)
j.Download(URL)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
ResultURL = j.GetString2("ISO-8859-1")
File.WriteString(xui.DefaultFolder, "demo.txt", ResultURL)
Dim List1 As List = File.ReadList(xui.DefaultFolder, "demo.txt")
For Each s As String In List1
Log(s)
Next
End If
This code by Oparra solved the problem
Thank you Oparra and Erel