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

Discussion in 'B4J Questions' started by MarkusR, Sep 1, 2018.

  1. MarkusR

    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:
    Code:
    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:
    Code:
    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
     
  2. OliverA

    OliverA Well-Known Member 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 likes this.
  3. MarkusR

    MarkusR Well-Known Member Licensed User

    ups. i missed to fill it. thank you.
    Code:
    req.InputStream.ReadBytes(buffer,0,buffer.Length)
     
    Last edited: Sep 1, 2018
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice