Created
January 10, 2021 07:16
-
-
Save SnowyPainter/97203412bc67d0ced5acddb75d06a67b to your computer and use it in GitHub Desktop.
This file contains hidden or 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:convert'; | |
| Future main() async { | |
| var server = await HttpServer.bind( | |
| InternetAddress.loopbackIPv4, | |
| 3000, | |
| ); | |
| print('Listening on localhost:${server.port}'); | |
| await for (HttpRequest request in server) { | |
| HttpResponse response = request.response; | |
| ContentType contentType = request.headers.contentType; | |
| if (request.method == 'POST' && | |
| contentType?.mimeType == 'application/xml') { | |
| try { | |
| String content = await utf8.decoder.bind(request).join(); | |
| print(content); | |
| } catch (e) { | |
| response | |
| ..statusCode = HttpStatus.internalServerError | |
| ..write('Exception during file I/O: $e.'); | |
| } | |
| } | |
| await response.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment