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

flutter http request

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

var url = Uri.parse('https://example.com/whatsit/create');
var response = await http.post(url, body: {'name': 'doodle', 'color': 'blue'});
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');

print(await http.read('https://example.com/foobar.txt'));
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

flutter http request

var client = http.Client();
try {
  var uriResponse = await client.post(Uri.parse('https://example.com/whatsit/create'),
      body: {'name': 'doodle', 'color': 'blue'});
  print(await client.get(uriResponse.bodyFields['uri']));
} finally {
  client.close();
}
Comment

flutter http request

class UserAgentClient extends http.BaseClient {
  final String userAgent;
  final http.Client _inner;

  UserAgentClient(this.userAgent, this._inner);

  Future<http.StreamedResponse> send(http.BaseRequest request) {
    request.headers['user-agent'] = userAgent;
    return _inner.send(request);
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: for in dart 
Dart :: const vs final flutter 
Dart :: remove item form list by index dart 
Dart :: flutter date timestamp 
Dart :: A dismissed Slidable widget is still part of the tree. 
Dart :: flutter icon 
Dart :: text substring dart 
Dart :: spacer in singlechildscrollview 
Dart :: convert double to string flutter 
Dart :: flutter disable touch 
Dart :: flutter snackbar top 
Dart :: get second to last item in a list dart 
Dart :: flutter get global context 
Dart :: dart is keyword 
Dart :: get first word of a string before space flutter 
Dart :: how can i deep copy in dart 
Dart :: split double value in dart 
Dart :: flutter random pick icon 
Dart :: How use late in Dart 
Dart :: collection for in dart 
Dart :: link failed but did not provide an info log flutter 
Dart :: how to set device into autorotate in flutter 
Dart :: Single document from firestore to a dart object 
Dart :: flutter thai language keyboard 
Dart :: inkwell not splashing in stack 
Swift :: on swipe get contentoffset swift collectionview 
Swift :: play sound in swift 5 
Swift :: custom screen presentation controller coner radius swift 
Swift :: swiftui delay 
Swift :: swift access appdelegate from viewcontroller 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =