HTTP POST status code 202 using Dart lang but no message in GrayLog

This curl works:

curl -XPOST http://192.168.1.14:12201/gelf -d ‘{“short_message”:“Hello there”, “host”:“example.org”, “facility”:“test”, “_foo”:“bar”}’

But using Dart and POSTing with HTTP returns status code 202:

import 'package:http/http.dart' as http;

Future<http.Response> createMessage() {
  return http.post(
    'http://192.168.1.14:12201/gelf',
    body: {
      'short_message': 'Hello there',
      'host': 'example.org',
      'facility': 'test',
      '_foo': 'bar'
    },
  );
}

I don’t see any messages from the Dart code.

Changed to this and it works:

import 'package:http/http.dart' as http;

Future<http.Response> createMessage() {
  const data = {
    'short_message': 'Hello there',
    'host': 'example.org',
    'facility': 'test',
    '_foo': 'bar'
  };
  final body = convert.jsonEncode(data);
  return http.post(
    'http://192.168.1.14:12201/gelf',
    body: body,
  );
}
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.