Commit c3f55dce authored by Collin Jackson's avatar Collin Jackson

Fix #104 by adding support for HTTP post using DataPipeFiller

parent aafce51e
// Copyright 2015, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/http.dart' as http;
import 'package:flutter/material.dart';
void main() {
runApp(
new MaterialApp(
title: "HTTP POST Example",
routes: {
'/': (RouteArguments args) => const PostDemo()
}
)
);
}
class PostDemo extends StatefulComponent {
const PostDemo();
PostDemoState createState() => new PostDemoState();
}
class PostDemoState extends State<PostDemo> {
String _response = null;
void initState() {
_refresh();
super.initState();
}
void _refresh() {
setState(() {
_response = null;
});
http.post("http://httpbin.org/post", body: "asdf=42").then((http.Response response) {
setState(() {
_response = response.body;
});
});
}
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text("HTTP POST example")
),
body: new Material(
child: new Block(
[new Text(
"${_response ?? 'Loading...'}",
style: Typography.black.body1
)]
)
),
floatingActionButton: new FloatingActionButton(
child: new Icon(
icon: 'navigation/refresh'
),
onPressed: _refresh
)
);
}
}
......@@ -70,8 +70,13 @@ class MojoClient {
mojo.UrlLoaderProxy loader = new mojo.UrlLoaderProxy.unbound();
mojo.UrlRequest request = new mojo.UrlRequest()
..url = url.toString()
..method = method
..body = body;
..method = method;
if (body != null) {
mojo.MojoDataPipe pipe = new mojo.MojoDataPipe();
request.body = <mojo.MojoDataPipeConsumer>[pipe.consumer];
ByteData data = new ByteData.view(UTF8.encode(body).buffer);
mojo.DataPipeFiller.fillHandle(pipe.producer, data);
}
try {
_networkService.ptr.createUrlLoader(loader);
mojo.UrlResponse response = (await loader.ptr.start(request)).response;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment