B4J Question StringUtils Base64 Problem on VPS / Session

Chris Guanzon

Active Member
Licensed User
Longtime User
Hello everyone. I have a problem with StringUtils using base64encode. It works fine on my local PC, but when I run it on my VPS, I get an error.

Here's the error message:

B4X:
(IllegalArgumentException) java.lang.IllegalArgumentException: Base64-encoded string must have at least four characters, but length specified was 3

Here is how I convert a string to a base64 string.

B4X:
dim s as string = "some text here"

s = SU.EncodeBase64(s.GetBytes("UTF8"))

This is how I decode it.

B4X:
s = BytesToString(SU.DecodeBase64(s), 0, SU.DecodeBase64(s).Length, "UTF8")
 

Chris Guanzon

Active Member
Licensed User
Longtime User
I found the problem; it is not about the base64, but rather about the session. It is not adding a session on the VPS, which is why it returns an error because the string returns "null". How can I fix this? Is there anything I need to install on my VPS?
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Longtime User
I cannot get the session on the server using the handler.

Login Hanlder:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    dim info as string = <some info here>
   
    req.GetSession.SetAttribute("info", info)
End Sub


User Info Handler:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    dim info as string = req.GetSession.GetAttribute("info")
   
    log("Info: " & info)
End Sub


Returns null value.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
The session depends on cookies. Check in your browser that you are receiving a cookie and that the cookie is not being deleted, may be you have some extreme privacy measure.
 
Upvote 0
Top