I try to sent data encoded with base64 to b4j server but the b4j server replaces the "+" character with " " of the base64 string.
How can i prevent this?
B4X:
Sub Process_Globals
Private su As StringUtils
Private ec As B4XCipher
End Sub
Private Sub request
Dim job As HttpJob
job.Initialize("", Me)
job.PostString(link&/req, "q="&su.EncodeBase64(ec.Encrypt("client".GetBytes("UTF8"),"server")))
Wait For (job) JobDone (j As HttpJob)
Log("J: " & j.Success)
If j.Success Then
MsgboxAsync(j.GetString, "Response")
End If
End Sub
Sub Handle (req As ServletRequest, resp As ServletResponse)
Dim q As String = req.GetParameter("q")
Log(q)
Dim su As StringUtils
Dim b() As Byte = su.DecodeBase64(q)
Dim r As String = BytesToString(b, 0, b.Length, "UTF8")
Log(r)
Dim m As Map = CreateMap("r": q)
resp.Write(m.As(JSON).ToCompactString)
End Sub
Client:
Sub PostTest
Dim job As HttpJob
job.Initialize("", Me)
Dim su As StringUtils
Dim value As String = su.EncodeBase64("测试".GetBytes("UTF8"))
Log(value)
Dim url As String = "http://127.0.0.1:8080"
job.PostString(url, "q=" & su.EncodeUrl(value, "UTF8"))
Wait For (job) JobDone (job As HttpJob)...
Can you please post here the same EncodeBase64 from B4J and from B4A in order for us not to create new programs to check it... (Also B4i version would be good). You might also want to post the code you use to Decode the data in order to propose some solutions.
I have tried sending url containing + but it is not replaced. I can't reproduce the issue.
You have posted the code for client. Please post the code for B4J server.
Sub Handle (req As ServletRequest, resp As ServletResponse)
Dim q As String = req.GetParameter("q")
Log(q)
Dim su As StringUtils
Dim b() As Byte = su.DecodeBase64(q)
Dim r As String = BytesToString(b, 0, b.Length, "UTF8")
Log(r)
Dim m As Map = CreateMap("r": q)
resp.Write(m.As(JSON).ToCompactString)
End Sub
Client:
Sub PostTest
Dim job As HttpJob
job.Initialize("", Me)
Dim su As StringUtils
Dim value As String = su.EncodeBase64("测试".GetBytes("UTF8"))
Log(value)
Dim url As String = "http://127.0.0.1:8080"
job.PostString(url, "q=" & su.EncodeUrl(value, "UTF8"))
Wait For (job) JobDone (job As HttpJob)
If job.Success Then
Dim response As Map = job.GetString.As(JSON).ToMap
Log(response.Get("r"))
End If
job.Release
End Sub