Search
 
SCRIPT & CODE EXAMPLE
 

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

Send HTTP Get request in Flutter or Dart

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

void main {
    final response = await http.get(Uri.parse("https://domain.com/endpoint?data=hello"));

    String responseData = utf8.decode(response.bodyBytes);

    print(json.decode(responseData));
}
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
Dart :: dart jsonencode list 
Dart :: dart integer division 
Dart :: underscore dart 
Dart :: dart check if object has property 
Dart :: flutter firestore crud 
Dart :: flutter flotingactionbutton extend 
Dart :: six_ft_apart_rounded 
Dart :: flutter container height 100 percent 
Dart :: dart data class generator 
Dart :: flutter listview builder space between items 
Dart :: dart reverse list 
Dart :: switch case dart 
Dart :: flutter datetime add year 
Dart :: what is final and const verabile in flutter 
Dart :: at this point the state of the widget element tree is no longer stable. flutter 
Dart :: error: xmlhttprequest error. dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 
Dart :: flutter listview inside a column 
Dart :: destructor in dart 
Dart :: mobx flutter 
Dart :: dart convert string to double 
Dart :: flutter toast 
Dart :: convert string date to datetime and format 
Dart :: flutter column in listview not working 
Dart :: return map dart 
Dart :: dart httop client 
Dart :: flutter appbar hide 
Dart :: http dart 
Dart :: carousel in flutter curved images onpressed 
Dart :: dart fold list 
Dart :: how to store special characters in dart string 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =