Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Last active December 17, 2019 16:43
Show Gist options
  • Select an option

  • Save r3dm1ke/3f8e366c3e6fb6f464281655ada2a49a to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/3f8e366c3e6fb6f464281655ada2a49a to your computer and use it in GitHub Desktop.
Sending POST requests in Dart/Flutter
import 'package:http/http.dart' as http;
// Sending a POST request
const url = 'https://some-api.com/users';
const payload = {online: false};
const response = await http.post(url, body: payload);
print(response.statusCode); // 200
// Sending a POST request with headers
const headers = {'Content-Type': 'application/json'};
const response_1 = await http.post(url, headers: headers, body: payload);
print(response_1.statusCode); // 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment