B4J Question HttpJob when Proxy is active

udg

Expert
Licensed User
Longtime User
Hi all,
I'm trying to deploy one of my sw in a very strictly controlled LAN where everything should pass through a proxy.
They ask me to integrate the ability to make use of their proxy in my sw.
What should I do?

As an example of data transmission, I have:
B4X:
Dim pJob As HttpJob
    pJob.Initialize("", Me)
    pJob.PostBytes(wscsync, buffer)
    Wait For (pJob) JobDone(j As HttpJob)

wscsync is:
Public const wscsync As String = "https://<mydomain>:62238/mnog"

Proxy needs authentication (user/password). What they can give me is:
proxy name/address
proxy port
proxy user (allowed to access Internet)
proxy password for user

I found the following code snippets on this forum, but I don't know how to use them (and whether they could be part of the solution):
B4X:
    SetSystemProperty("http.proxyHost","webwasher.xxxx.com")
    SetSystemProperty("https.proxyHost", "webwasher.xxx.com")
    SetSystemProperty("http.proxyPort", 3128)
    SetSystemProperty("https.proxyPort", 3128)
    SetSystemProperty("https.proxyUser",  <username>)
    SetSystemProperty("https.proxyPassword", <pwd>")

Sub SetProxy (hc As OkHttpClient, Host As String, Port As String)
    Dim jo As JavaObject = hc
    Dim proxy, socketaddress As JavaObject
    socketaddress.InitializeNewInstance("java.net.InetSocketAddress", Array(Host, Port))
    proxy.InitializeNewInstance("java.net.Proxy", Array("HTTPS", socketaddress))
    jo.GetFieldJO("client").RunMethod("setProxy", Array(proxy))
End Sub

Please, note the use of HTTPS (original code was for HTTP).

TIA
 

udg

Expert
Licensed User
Longtime User
Thank ypu, @Erel
We are investigating more deeply. as a temporary solution (tomorrow everything should work ok) they are planning to set up a simpler proxy for me.
It will not act in any way on my packets. It will be like (more or less) to access the external server directly
Let's hope at least this one works correctly as soon a sit is deployed.

udg
 
Upvote 0
Top