dart:io
庫中HttpClientRequest.abort
方法的用法介紹如下。
用法:
@Since("2.10")
void abort(
[Object? exception,
StackTrace? stackTrace]
)
@Since("2.10")
中止客戶端連接。
如果連接尚未完成,則中止請求,並使用提供的 exception
和 stackTrace
完成 done 未來(也由 close 返回)。如果省略exception
,則默認為HttpException,如果省略stackTrace
,則默認為StackTrace.empty。
如果 done 未來已經完成,則中止無效。
中止請求後,使用 IOSink 方法(例如 write 和 add )無效
var client = HttpClient();
HttpClientRequest request = await client.get('localhost', 80, '/file.txt');
request.write('request content');
Timer(Duration(seconds: 1), () {
request.abort();
});
request.close().then((response) {
// If response comes back before abort, this callback will be called.
}, onError: (e) {
// If abort() called before response is available, onError will fire.
});
相關用法
- Dart HttpClientRequest.followRedirects用法及代碼示例
- Dart HttpClientRequest用法及代碼示例
- Dart HttpClientResponse用法及代碼示例
- Dart HttpClient.findProxy用法及代碼示例
- Dart HttpClient用法及代碼示例
- Dart HttpClient.findProxyFromEnvironment用法及代碼示例
- Dart HttpClient.connectionFactory用法及代碼示例
- Dart HttpClient.keyLog用法及代碼示例
- Dart HttpRequest.postFormData用法及代碼示例
- Dart HttpOverrides用法及代碼示例
- Dart HttpServer.defaultResponseHeaders用法及代碼示例
- Dart HttpRequest.request用法及代碼示例
- Dart HttpDate.parse用法及代碼示例
- Dart HttpRequest用法及代碼示例
- Dart HttpHeaders用法及代碼示例
- Dart HttpServer用法及代碼示例
- Dart HttpRequest.getString用法及代碼示例
- Dart HttpRequest構造函數用法及代碼示例
- Dart HttpResponse用法及代碼示例
- Dart HtmlCollection.last用法及代碼示例
- Dart HtmlEscape用法及代碼示例
- Dart HtmlEscapeMode用法及代碼示例
- Dart HtmlCollection.elementAt用法及代碼示例
- Dart HtmlCollection.length用法及代碼示例
- Dart HtmlDocument.registerElement2用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 abort method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。