Android Question Response.GetString("UTF8") problem

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi
been away for some time...
just updated to 7.30 and reinstall the entire package.
have an app that is up & running and i need to make a few light modifications
so when opened the project i got this error - Response.GetString("UTF8")
been reading and saw that there are new libs ok...
tried to use the new libs but it made a lot of issues so i decided to roll back to my working code
how can i just overcome this issue ?

thanks
 
Or you use Response.GetString2("UTF8") or simply Response.GetString
 
Upvote 0
i think i'm confused...

this is my routine

Sub webClient_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)

resultSoapXML = Response.GetString("UTF8")

Log("Success : " & resultSoapXML)

End Sub

and getstring is the problematic part
 
Upvote 0
yes,
i use a web service to process some info
this app is working fine but since the version something went wrong - i guess due to some internal changes
the question is how can i resolve this without rewriting my entire app (or its communications module) ?
 
Upvote 0
Upvote 0
to be frank - i don't think i am capable to modify them...

i just need a way to be able to modify my code with a minor change
this is problematic.

is there a way to re-use http & httputil instead of okhttp and okhttputil ?
as in the older libs all was working fine for me
 
Upvote 0
at least with android 5+ you MUST update to okhttp.
So; if you plan to use it in the future then you need to use okHttp and okhttputils
 
Upvote 0
Well, after having taken a look at the code modules, why not trying using Response.GetAsynchronously and when the event is reached reading the resulting file with a TextReader (specifying the desired encoding) as it is done in HttpJob for GetString2.
But I must say it seems to be (for me) much cumbersome than modifying some code to use the already done libraries.
 
Upvote 0
this is a sample i use - just a simple ping function to my server web service


Sub MTS_Ping()
Dim sXML As String

sXML = _
"<?xml version='1.0' encoding='utf-8'?>" & _
"<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" & _
"<soap12:Body>" & _
"<MTS_Ping xmlns='https://mywebserviceurl.com/'>" & _
"<Element1>"&Element1&"</Element1>" & _
"<Element2>"&element2&"</Element2>" & _
"</MTS_Ping>" & _
"</soap12:Body>" & _
"</soap12:Envelope>"


webRequest.InitializePost2(URL, sXML.GetBytes("UTF8"))

webRequest.Timeout = 10000

webRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")

If webClient.Execute(webRequest,1) = False Then Return

'WS function went OK
' some other operations comes here

End Sub


Sub webClient_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)

Response.GetAsynchronously("Proc_StreamFinish", File.OpenOutput(File.DirDefaultExternal, "OK.txt", False), True, TaskId)

End Sub


Sub Proc_StreamFinish (Success As Boolean, TaskId As Int)

If Success = True Then

resultSoapXML= File.ReadString(File.DirDefaultExternal, "OK.txt")
Log("Success : " & resultSoapXML)
WebServiceResult = True

Else

resultSoapXML= File.ReadString(File.DirDefaultExternal, "FAIL.txt")

WebServiceResult = False
Msgbox ("Error" & CRLF & resultSoapXML, "Error")

End If
End Sub


Sub webClient_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)

Response.GetAsynchronously("ProcCC_StreamFinish", File.OpenOutput(File.DirDefaultExternal, "FAIL.txt", False), True, TaskId)

End Sub




in my old application (using hhtp and httputils) it was all working just fine
now afeter changing to okhttp & okhttputil and modifying to this code as i couldnot use response.getstring anymore i get
the following error


415
Unsupported Media

what am i missing or doing wrong ?

thanks
 
Upvote 0
Please use the [code]...[/code] tags when posting code, or, attach your code as a ZIP file (You have that feature on the IDE).

Also, why are you doing this?:
Code: Copy
Sub webClient_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)

 Response.GetAsynchronously("ProcCC_StreamFinish", File.OpenOutput(File.DirDefaultExternal, "FAIL.txt", False), True, TaskId)

 End Sub
The reason for failure is in "Reason As String" you could just display that on the screen.
 
Last edited:
Upvote 0
Please use the [code]...[/code] tags when posting code, or, attach your code as a ZIP file (You have that feature on the IDE).

Also, why are you doing this?:
Code: Copy
Sub webClient_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)

Response.GetAsynchronously("ProcCC_StreamFinish", File.OpenOutput(File.DirDefaultExternal, "FAIL.txt", False), True, TaskId)

End Sub
The reason for failure is in "Reason As String" you could just display that on the screen.

thank you, sorry and appology for the code style...
i think i'm still missing something - what is wrong with the reason i used and how should i fix it ?
 
Upvote 0
It will take you 10 minutes to switch to OkHttpUtils2. There is no reason to use HttpClient or OkHttpClient directly.

With that said you can still use HttpClient (Http library). Just make sure to compile with android.jar version 22 or below.
However Response.GetString will throw an exception unless you implement the NetworkOnMainThread workaround.

The correct solution is to switch to OkHttpUtils2 and use it with Wait For.
 
Upvote 0
thank you all for your input.
indeed it seems i will have no other option than to rewrite the entire comms part
so back to school - for OkHttpUtils2

once again thank you all
 
Upvote 0
Back
Top