Created
March 24, 2019 10:32
-
-
Save trunghieuvn/8cfa287c8169ae3cfd68a7d32eaca193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'dart:async'; | |
import 'dart:convert' show utf8; | |
import 'package:mysql1/mysql1.dart'; | |
import 'AccountModel.dart'; | |
List<Map<String, dynamic>> convertToMapUser(Results result) { | |
List<Map<String, dynamic>> users = new List(); | |
for (var row in result) { | |
users.add(new AccountModel(row[0], row[1].toString()).toJson()); | |
} | |
return users; | |
} | |
Future main() async { | |
var server = await HttpServer.bind(InternetAddress.loopbackIPv6, 4042); | |
print('Listening on localhost:${server.port}'); | |
await for (HttpRequest req in server) { | |
if(req.method == "GET") { | |
req.response | |
..write('Hello, world! : ' + req.uri.queryParameters['name']) | |
..close(); | |
} | |
if (req.method == 'POST' && | |
req.headers.contentType.toString() == 'application/json') { | |
var content = await req.transform(utf8.decoder).toList(); | |
var val = content; | |
var y = "Có dữ liệu"; | |
if (val == null || val.isEmpty) { | |
y = "Ko nhan dc json"; //this is empty value | |
} | |
var x = await req.transform(utf8.decoder); | |
//print(y); | |
req.response | |
..write(val) | |
..write(val.length) | |
..close(); | |
} | |
} | |
} |
Author
trunghieuvn
commented
Mar 24, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment