Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

428
Vistas
How to send Binary encrypted data in flutter POST with request encoding :null ? ; which is working in node js properly

According to node.js Documentation encoding : null when binary data to be sent via Api,

https://www.npmjs.com/package/request in this link below mentioned explanation is found.

encoding - encoding to be used on setEncoding of response data. If null, the body is returned as a Buffer. Anything else (including the default value of undefined) will be passed as the encoding parameter to toString() (meaning this is effectively utf8 by default).

Note: if you expect binary data, you should set encoding: null.

Now I have achieve the same thing in flutter/dart and this encoding parameter is not accepting null as here in node.js they have mentioned.

I want to know how to make this same Post request from Flutter/dart or at least android/java.

var enc = AESCrypt.encrypt(key, iv, JSON.stringify(obj_j));

var output = new Buffer.from(enc, 'hex'); // Buffer 

function test() {
    console.time("XXX");
    request.post({
   
        headers: {
            'content-type': 'application/json'
        },  //required, or webserver will ignore it application/json  multipart/form-data
        url: 'http://192.168.29.210/deviceid/read', // webserver url
        encoding:null,
        body: output
    },
    function (error, response, body) {
        
        if (!error && response.statusCode == 200) {
             console.timeEnd("XXX");
           
            body = AESCrypt.decrypt(key, iv, body);
             //body is decrypted http response, can be parsed with json method
            fs.writeFile('input.json', body, function (err) {
                if (err) {
                    return console.error(err);
                }
            });
        }
    });

};

Adding code the What i have tried in flutter

    var headers = {'Content-Type': 'application/json'};

    var request =
        http.Request('POST', Uri.parse('http://192.168.29.210/deviceid/read'));
    request.body = encryptedText;
    request.encoding = null ; // here this null parameter is not acceptable 
    request.encoding = Encoding.getByName("utf-8")); // only this option is available to add in flutter 
    request.headers.addAll(headers);

    http.StreamedResponse response = await request.send();

Even in post man this encoding variable is not present to set it.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Use below flutter framework method

Future<Response> post(Uri url,
    {Map<String, String>? headers, Object? body, Encoding? encoding}) =>
_withClient((client) =>
    client.post(url, headers: headers, body: body, encoding: encoding));

How to use

  final url = Uri.parse('$urlPrefix/posts');
  final headers = {"Content-type": "application/json"};
  final json = '{"title": "Hello", "body": "body text", "userId": 1}';
  final response = await post(url, headers: headers, body: json,encoding:null);  //here this null parameter is not acceptable 
over 4 years ago · Santiago Trujillo Denunciar

0

My Final working code is

var headers = {'Content-Type': 'application/json'};

    final response = await http.post(
        Uri.parse('http://192.168.29.210/deviceid/read'),
        headers: headers,
        body: encryptedText,
        encoding: null);
    if (response.statusCode == 200) {
      String res = response.body.toString();
      //String data = AesEncryption().decryption(res);
      print('Body: ${response.body.toString()}');
    } else {
      print(response.reasonPhrase);
    }
    print('Status code: ${response.statusCode}');
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda