Home > Net >  decode buffer response from GET dart/flutter
decode buffer response from GET dart/flutter

Time:02-10

I am very new in the dart programming language. I'm trying to build a flutter android app that gets a calendar from a server. I've been trying to solve this problem for 2 days but I don't really understand what is going on and what I'm doing wrong. So basically in the first request I get the token and session_id, which I later include in the 2nd (GET) request. The server returns the data in different packets which I should combine in a buffer. The buffer is gzip encoded and includes JSON data about the calendar. First I tried to make this work in node.js, which I did using this code:

var buffer = [];
const req = https.request(options, res => {
    res.on('data', d => {
        buffer.push(d);
    })
    res.on('close', () => {
        buffer = Buffer.concat(buffer);
        zlib.gunzip(buffer, (err, buffer) => {
            makeCalendar(JSON.parse(buffer.toString('utf-8')));
        });
    })
})
req.on('error', error => {
    console.error(error)
})
req.end()

It works perfectly. But when I tried to do it in dart it didn't go as expected. I tried using the http.dart package and dart:io package. Any ideas how I could do this?

CodePudding user response:

  •  Tags:  
  • Related