B4J Question [solved] jServer receive bytes() from client?

MarkusR

Well-Known Member
Licensed User
hello,
i will send bytes from a client app to my server but at receive i got error
java.util.zip.ZipException: unknown compression method
Obj = ser.ConvertBytesToObject(buffer)

Client:
B4X:
Sub Save(Item As SinglePassword)
    
    Dim Data() As Byte

    Dim ser As B4XSerializator
    Data = ser.ConvertObjectToBytes(Item)

    Dim Job As HttpJob
    Job.Initialize("",Me)
    Job.Username = Main.Username
    Job.Password = Main.Password
    Job.PostBytes("https://" & Main.Server & "/request/save",Data) '?cmd=save
    
    Wait For (Job) JobDone(Job As HttpJob)
    If Job.Success Then
    Else
        xui.MsgboxAsync("Save Failed","Error")       
    End If
    Job.Release
    
End Sub
jServer:
B4X:
srvr.AddHandler("/request/save", "Save", False)

Sub Handle(req As ServletRequest, resp As ServletResponse)

    Log(req.FullRequestURI)

    Dim ser As B4XSerializator
    
    Dim Obj As Object
    Dim buffer(req.InputStream.BytesAvailable) As Byte
    Obj = ser.ConvertBytesToObject(buffer)

    Dim Item1 As SinglePassword
    Item1 = Obj

    Dim Manager As PasswordManager
    Manager.Initialize
    Manager.Save(Item1)

    resp.Write("ok save " & Item1.Id & " " & Item1.Name)
            
End Sub
 

OliverA

Expert
Licensed User
You declared an empty buffer with a size of available bytes. You then feed this empty buffer to the serializer, which causes your error message.
 

MarkusR

Well-Known Member
Licensed User
ups. i missed to fill it. thank you.
B4X:
req.InputStream.ReadBytes(buffer,0,buffer.Length)
 
Last edited:
Top