Hello all, i'am trying to set a proxy using the httputils class, but am not having so much luck, the problem is that the url i'am trying to access only accept national requests, and as i'am outside of that country i always get an error, i found a code example given by @Erel, but i'am getting this error, i'm not sure if this code can only be used for B4J or if it can be used in B4A as well, any help will be greatly appreciated.
Here's the error I receive
And here is the code i'm referring to:
Thanks everyone!
Walter
Here's the error I receive
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
httputils2service_setproxy (B4A line: 34)
jo.GetFieldJO("client").RunMethod("setProxy", Arr
java.lang.RuntimeException: Method: setProxy not found in: okhttp3.OkHttpClient
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at com.genesis.buscadordeplacas.httputils2service._setproxy(httputils2service.java:346)
at com.genesis.buscadordeplacas.httputils2service._submitjob(httputils2service.java:382)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1151)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
And here is the code i'm referring to:
B4X:
Sub SetProxy (hc1 As OkHttpClient, Host As String, Port As Int)
Dim jo As JavaObject = hc1
Dim proxy, socketAddress As JavaObject
socketAddress.InitializeNewInstance("java.net.InetSocketAddress", Array (Host, Port))
proxy.InitializeNewInstance("java.net.Proxy", Array ("HTTP", socketAddress))
jo.GetFieldJO("client").RunMethod("setProxy", Array(proxy))
End Sub
Thanks everyone!
Walter