Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
        }),
    );
}
Comment

post flutter

Post postFromJson(String str) {    
   final jsonData = json.decode(str);    
   return Post.fromJson(jsonData);
}
Comment

http post in flutter

dependencies:
  http: <latest_version>
Comment

How to send post request using http in flutter

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

Future<http.Response> postRequest () async {
  var url ='https://pae.ipportalegre.pt/testes2/wsjson/api/app/ws-authenticate';

  Map data = {
    'apikey': '12345678901234567890'
  }
  //encode Map to JSON
  var body = json.encode(data);

  var response = await http.post(url,
      headers: {"Content-Type": "application/json"},
      body: body
  );
  print("${response.statusCode}");
  print("${response.body}");
  return response;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react useeffect hooks 
Javascript :: javascript eingabe in inputfielder übernehmen 
Javascript :: how to take input n number in js 
Javascript :: jest cross origin localhost fobbiden 
Javascript :: chrome storage local update 
Javascript :: jest Cross origin http://localhost forbidden 
Javascript :: react set initial state without constructor 
Javascript :: JavaScript catch() method 
Javascript :: pug iterate array 
Javascript :: alpine js x-on click not working 
Javascript :: make shorter if statements with objects 
Javascript :: obfuscate js string 
Javascript :: javascript string length 
Javascript :: how to get 6 months after date object 
Javascript :: sequelize db:create test environment 
Javascript :: jquery select 
Javascript :: adding event listener to multiple elements 
Javascript :: server mail 
Javascript :: search node in tree javascript 
Javascript :: mapStateProps 
Javascript :: js reading file 
Javascript :: postman environment variable 
Javascript :: upload bloob javascript 
Javascript :: spam system discord.js 
Javascript :: create variable javascript 
Javascript :: javascript entries() method 
Javascript :: connectedcallback web components 
Javascript :: object loop 
Javascript :: document get element by id hover 
Javascript :: how to add changes every time you route navigate to page in angular 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =