Android Question httpserver

catyinwong

Active Member
Licensed User
Longtime User
I am testing with the httpserver library with local host, and try to post http jobs to the server but the connection failed with the error:

B4X:
 ResponseError. Reason: javax.net.ssl.SSLHandsshakeException: Handshake failed, Response:

I did some search on the issue and found many suggestions about "initializeacceptall" but I am confused where I can add that?
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
Yes, that's what I am confused.

I m now using OkhttpUtils2 but I cant see anywhere for initializeacceptall
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You are doing something wrong when you use the sourcecode!

Go again over the tutorial, add the HU2_ACCEPTALL conditional symbol in the Buildconfigurations.
REMOVE the sourcemodules. Only use the Library.
Also make sure to use the newest version of B4A (10.0 as of now).
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
You are doing something wrong when you use the sourcecode!

Go again over the tutorial, add the HU2_ACCEPTALL conditional symbol in the Buildconfigurations.
REMOVE the sourcemodules. Only use the Library.
Also make sure to use the newest version of B4A (10.0 as of now).


The tutorial says the jars are in B4J internal libraries but they are not. The best I can Google is httpclient V4.2.5 and http core V4.0, still far from the needed versions....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The tutorial says the jars are in B4J internal libraries but they are not.
The okhttputils2.b4xlib, okhttputils2.jar and okhttputils2.xml ARE/IS inside the internal library folder.

No need(!) to google for any httpclient. It is not relevant.
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
The okhttputils2.b4xlib, okhttputils2.jar and okhttputils2.xml ARE/IS inside the internal library folder.

No need(!) to google for any httpclient. It is not relevant.

so the followings are not needed?

B4X:
#AdditionalJar: httpclient-4.5.2 
#AdditionalJar: httpcore-4.4.4 
#AdditionalJar: commons-codec-1.9
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
WHICH Thread? Which library?

it is the example link under the tutorial thread. never mind if the additional jars are not needed.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
And for the SSL, how do I know if my device have it or how do I build it?
Do you access your intranet web services using http or https?
I am testing with the httpserver library with local host, and try to post http jobs to the server
I am confused. You said you are testing in local host. How do you test it? Do you create a B4J app to connect to your localhost (IP=127.0.0.1) or connect to another server with different IP?
 
Upvote 0

catyinwong

Active Member
Licensed User
Longtime User
Do you access your intranet web services using http or https?

I am confused. You said you are testing in local host. How do you test it? Do you create a B4J app to connect to your localhost (IP=127.0.0.1) or connect to another server with different IP?

I add a menu item at the main activity, and which start a http job to put string to the localhost.

so the codes are within the same app
 
Upvote 0

Muhamad Kamal

Member
Licensed User
I have been facing the same problem for a while with my Oreo (Android v8) tablet.. but after updating my codes by following the thread below I'm now able to connect to my https server.


It seems that my Oreo tablet did install the security provider and everything is ok now.. thanks to the guru Erel.. ???

Note: In my case adding the HU2_ACCEPTALL did not solve the problem as it was something to do with the protocol library.

Added to Main::
#AdditionalJar: com.google.android.gms:play-services-base

Added to Starter::
Sub Service_Create
    Config.ServiceCreate
    
    'installing Security Provider if needed
        Dim jo As JavaObject
        jo.InitializeStatic("com.google.android.gms.security.ProviderInstaller")
        Dim context As JavaObject
        context.InitializeContext
        DisableStrictMode
        Dim listener As Object = jo.CreateEventFromUI("com.google.android.gms.security.ProviderInstaller.ProviderInstallListener", _
            "listener", Null)
        Log("Installing security provider if needed...")
        jo.RunMethod("installIfNeededAsync", Array(context, listener))
        Wait For listener_Event (MethodName As String, Args() As Object)
        If MethodName = "onProviderInstalled" Then
            Log("Provider installed successfully")
        Else
            Log("Error installing provider: " & Args(0))
        End If
End Sub

Sub DisableStrictMode
        Dim jo As JavaObject
        jo.InitializeStatic("android.os.Build.VERSION")
        If jo.GetField("SDK_INT") > 9 Then
            Dim policy As JavaObject
            policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
            policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
            Dim sm As JavaObject
            sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
        End If
End Sub

Sub ws_Closed (Reason As String)
    Log("error: " & Reason)
End Sub
 
Last edited:
Upvote 0
Top