Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

Send HTTP POST request in Flutter or Dart

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

void main() async {
    http.Response response = await createUser("Bob", "engineer");
    
    print(response.body);
}

Future<http.Response> createUser(String name, String job) {
    return http.post(
        Uri.parse('https://reqres.in/api/users'),
        headers: <String, String>{
            'Content-Type': 'application/json; charset=UTF-8',
        },
        body: jsonEncode(<String, String>{
            'name': name,
            'job': job
        }),
    );
}
Source by devsheet.com #
 
PREVIOUS NEXT
Tagged: #Send #HTTP #POST #request #Flutter #Dart
ADD COMMENT
Topic
Name
4+4 =