Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created January 10, 2021 07:16
Show Gist options
  • Save SnowyPainter/97203412bc67d0ced5acddb75d06a67b to your computer and use it in GitHub Desktop.
Save SnowyPainter/97203412bc67d0ced5acddb75d06a67b to your computer and use it in GitHub Desktop.
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