Android Question HttpServer library how use Https

Lello1964

Well-Known Member
Licensed User
Longtime User
Hi,
I am using the HttpServer library to communicate with a web application,
I would like to know how to use the Https protocol with an SSLcertificate.

Raffaele
 

OliverA

Expert
Licensed User
Longtime User
I need to start it myself.
You may not need to. As is, HttpServer's Start method sets some items up. After starting the HttpServer via the Start method (and letting it set up most of the things for the server object without you having to recreate/implement everything from scratch), you can stop the server (via Reflection, not HttpServer's Stop method), activate your SSL and restart the server via Reflection (don't use HttpServer's Start method, since it would create a new underlying server object, negating all your hard work).
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
You may not need to. As is, HttpServer's Start method sets some items up. After starting the HttpServer via the Start method (and letting it set up most of the things for the server object without you having to recreate/implement everything from scratch), you can stop the server (via Reflection, not HttpServer's Stop method), activate your SSL and restart the server via Reflection (don't use HttpServer's Start method, since it would create a new underlying server object, negating all your hard work).
Seems like a good solution but at first it generates an error here:
B4X:
Public Sub SetupSSL
    Dim r As Reflector
    r.Target = server
    Dim O As Object = r.GetField("server")
    r.Target = r.GetField("server")    'Get private server object
    r.RunMethod("stop")
    
    Dim J As JavaObject = Me

    j.RunMethod("active_ssl", Array(O)) <--- Error
    r.RunMethod("start") 'Restart server after setting up SSL
End Sub

java.lang.IllegalArgumentException: Expected receiver of type it.tecnomedia.sslserver.serverservice, but got java.lang.Class<it.tecnomedia.sslserver.serverservice>
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Try
B4X:
Dim j as JavaObject
j.InitializeContext
j.RunMethod("active_ssl", Array(0))
Note: Untested
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thanks for your help, it was very helpful in correcting some mistakes I made.

Now I have to study a little to get the job done.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I have found that the httpserver library is not open source like the jserver library

To continue the work you must have the consent of @Erel. I apologize if I went beyond what I was allowed
 
Upvote 0

swChef

Active Member
Licensed User
Longtime User
Has anyone extended the source www.b4x.com/android/files/HttpServer_src.zip to support https ?

@Star-Dust my other option seems to be the source to xhttpserver, or have you considered adding ssl to that? [no per SD]

I do have a need to receive https posts from another android application, which has a send to server functionality.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Has anyone extended the source to support https ?
@Star-Dust my other option seems to be the source to xhttpserver, or have you considered adding ssl to that?

I do have a need to receive https posts from another android application, which has a send to server functionality.
This library is written entirely in B4X, it does not rely on native libraries or existing classes in the system. So to add TLS / SSL you have to build it from scratch. I could not understand the protocol and therefore it was not possible. Among other things, now I am following other projects and I do not have the time to study a way to obtain it.

You can use Digest security, if that's enough, which I have implemented (all in B4X of course) and it works fine.
 
Upvote 0
Top