OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 | 5 |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:uri"; | 7 import "dart:uri"; |
8 | 8 |
9 main() { | 9 main() { |
10 bool serverOnClosed = false; | 10 bool serverOnClosed = false; |
(...skipping 17 matching lines...) Expand all Loading... |
28 response.outputStream.onClosed = () { | 28 response.outputStream.onClosed = () { |
29 serverOnClosed = true; | 29 serverOnClosed = true; |
30 checkDone(); | 30 checkDone(); |
31 }; | 31 }; |
32 response.outputStream.writeString("hello!"); | 32 response.outputStream.writeString("hello!"); |
33 response.outputStream.close(); | 33 response.outputStream.close(); |
34 }; | 34 }; |
35 }; | 35 }; |
36 | 36 |
37 var connection = client.postUrl( | 37 var connection = client.postUrl( |
38 new Uri.fromString("http://127.0.0.1:${server.port}")); | 38 Uri.parse("http://127.0.0.1:${server.port}")); |
39 connection.onError = (e) { throw e; }; | 39 connection.onError = (e) { throw e; }; |
40 connection.onRequest = (request) { | 40 connection.onRequest = (request) { |
41 request.contentLength = "hello!".length; | 41 request.contentLength = "hello!".length; |
42 request.outputStream.onError = (e) { throw e; }; | 42 request.outputStream.onError = (e) { throw e; }; |
43 request.outputStream.onClosed = () { | 43 request.outputStream.onClosed = () { |
44 clientOnClosed = true; | 44 clientOnClosed = true; |
45 checkDone(); | 45 checkDone(); |
46 }; | 46 }; |
47 request.outputStream.writeString("hello!"); | 47 request.outputStream.writeString("hello!"); |
48 request.outputStream.close(); | 48 request.outputStream.close(); |
49 }; | 49 }; |
50 connection.onResponse = (response) { | 50 connection.onResponse = (response) { |
51 response.inputStream.onData = response.inputStream.read; | 51 response.inputStream.onData = response.inputStream.read; |
52 response.inputStream.onClosed = () { | 52 response.inputStream.onClosed = () { |
53 requestOnClosed = true; | 53 requestOnClosed = true; |
54 checkDone(); | 54 checkDone(); |
55 }; | 55 }; |
56 }; | 56 }; |
57 } | 57 } |
OLD | NEW |