B4J Question set Proxy to avoid CORS

Patent

Member
Licensed User
Longtime User
Dear community,

wanna use a local Proxy in B4J to avoid CORS Problems.
This is the Try:
B4X:
Sub Process_Globals
    Dim ho As String
    Dim po As Int
End Sub

Sub AppStart (Args() As String)
    ho="192.168.043.075"    'local ip
    po=8080
 
    Dim j As HttpJob
    j.Initialize("j", Me)
    'SetSystemProperty("http.proxyHost", "localhost")
    'SetSystemProperty("http.proxyPort", "8080")
 
    j.Download("https://www.b4x.com/images/Logo_on-dark.png")
 
    StartMessageLoop
End Sub

Sub JobDone(j As HttpJob)
    Log(j.GetString)
    StopMessageLoop
End Sub

with the Initialize Sub in HttpUtils2Service:
B4X:
Sub Initialize
    If hc.IsInitialized = False Then
        TempFolder = File.DirTemp
        Dim jo As JavaObject = hc
        Dim proxy, socketAddress As JavaObject
        socketAddress.InitializeNewInstance("java.net.InetSocketAddress", Array (Main.Ho, Main.Po))
        proxy.InitializeNewInstance("java.net.Proxy", Array ("HTTP", socketAddress))
        Dim builder As JavaObject = jo.RunMethod("sharedInit", Array("hc"))

        builder.RunMethod("proxy", Array(proxy)) '<---- fixed!!!
        jo.SetField("client", builder.RunMethod("build", Null))
        TaskIdToJob.Initialize
    End If
End Sub

Error: java.net.ConnectException: Failed to connect to /192.168.43.75:8080

Whats the fault?
Help appreciated

greets
 

Attachments

  • proxy.zip
    4.1 KB · Views: 376
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…