| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A utility for retrieving data from a URL. | 8 * A utility for retrieving data from a URL. |
| 9 * | 9 * |
| 10 * HttpRequest can be used to obtain data from http, ftp, and file | 10 * HttpRequest can be used to obtain data from http, ftp, and file |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 */ | 47 */ |
| 48 static Future<String> getString(String url, | 48 static Future<String> getString(String url, |
| 49 {bool withCredentials, void onProgress(ProgressEvent e)}) { | 49 {bool withCredentials, void onProgress(ProgressEvent e)}) { |
| 50 return request(url, withCredentials: withCredentials, | 50 return request(url, withCredentials: withCredentials, |
| 51 onProgress: onProgress).then((xhr) => xhr.responseText); | 51 onProgress: onProgress).then((xhr) => xhr.responseText); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Makes a server POST request with the specified data encoded as form data. | 55 * Makes a server POST request with the specified data encoded as form data. |
| 56 * | 56 * |
| 57 * This is similar to sending a FormData object with broader browser | 57 * This is roughly the POST equivalent of getString. This method is similar |
| 58 * support but limited to string values. | 58 * to sending a FormData object with broader browser support but limited to |
| 59 * String values. |
| 59 * | 60 * |
| 60 * See also: | 61 * See also: |
| 61 * | 62 * |
| 62 * * [request] | 63 * * [request] |
| 63 */ | 64 */ |
| 64 static Future<HttpRequest> postFormData(String url, Map<String, String> data, | 65 static Future<HttpRequest> postFormData(String url, Map<String, String> data, |
| 65 {bool withCredentials, String responseType, | 66 {bool withCredentials, String responseType, |
| 66 Map<String, String> requestHeaders, | 67 Map<String, String> requestHeaders, |
| 67 void onProgress(ProgressEvent e)}) { | 68 void onProgress(ProgressEvent e)}) { |
| 68 | 69 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 | 82 |
| 82 return request(url, method: 'POST', withCredentials: withCredentials, | 83 return request(url, method: 'POST', withCredentials: withCredentials, |
| 83 responseType: responseType, | 84 responseType: responseType, |
| 84 requestHeaders: requestHeaders, sendData: formData, | 85 requestHeaders: requestHeaders, sendData: formData, |
| 85 onProgress: onProgress); | 86 onProgress: onProgress); |
| 86 } | 87 } |
| 87 | 88 |
| 88 /** | 89 /** |
| 89 * Creates a URL request for the specified [url]. | 90 * Creates a URL request for the specified [url]. |
| 90 * | 91 * |
| 91 * By default this will do an HTTP GET request, this can be overridden with | 92 * By default `request` will perform an HTTP GET request, but a different |
| 92 * [method]. | 93 * method (`POST`, `PUT`, `DELETE`, etc) can be used by specifying the |
| 94 * [method] parameter. |
| 93 * | 95 * |
| 94 * The Future is completed when the response is available. | 96 * The Future is completed when the response is available. |
| 95 * | 97 * |
| 98 * If specified, `sendData` will send data in the form of a [ByteBuffer], |
| 99 * [Blob], [Document], [String], or [FormData] along with the HttpRequest. |
| 100 * |
| 96 * The [withCredentials] parameter specified that credentials such as a cookie | 101 * The [withCredentials] parameter specified that credentials such as a cookie |
| 97 * (already) set in the header or | 102 * (already) set in the header or |
| 98 * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2) | 103 * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2) |
| 99 * should be specified for the request. Details to keep in mind when using | 104 * should be specified for the request. Details to keep in mind when using |
| 100 * credentials: | 105 * credentials: |
| 101 * | 106 * |
| 102 * * Using credentials is only useful for cross-origin requests. | 107 * * Using credentials is only useful for cross-origin requests. |
| 103 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca
rd (*). | 108 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca
rd (*). |
| 104 * * The `Access-Control-Allow-Credentials` header of `url` must be set to tru
e. | 109 * * The `Access-Control-Allow-Credentials` header of `url` must be set to tru
e. |
| 105 * * If `Access-Control-Expose-Headers` has not been set to true, only a subse
t of all the response headers will be returned when calling [getAllRequestHeader
s]. | 110 * * If `Access-Control-Expose-Headers` has not been set to true, only a subse
t of all the response headers will be returned when calling [getAllRequestHeader
s]. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } else { | 267 } else { |
| 263 JS('', '#.send()', xhr); | 268 JS('', '#.send()', xhr); |
| 264 } | 269 } |
| 265 | 270 |
| 266 return completer.future; | 271 return completer.future; |
| 267 $endif | 272 $endif |
| 268 } | 273 } |
| 269 | 274 |
| 270 $!MEMBERS | 275 $!MEMBERS |
| 271 } | 276 } |
| OLD | NEW |