클라이언트에서 URL (dart:html
)을 가져 오는 것이 straightforward 인 경우 서버 측 (dart:io
)에는 편리한 getString
메소드가 없습니다.다트 서버 (다트 : io)에서 URL을 가져 오는 방법은 무엇입니까?
간단히 URL 문서를 문자열로로드하는 방법은 무엇입니까?
import "dart:io";
import "dart:async";
import "dart:convert";
Future<String> fetch(String url) {
var completer = new Completer();
var client = new HttpClient();
client.getUrl(Uri.parse(url))
.then((request) {
// Just call close on the request to send it.
return request.close();
})
.then((response) {
// Process the response through the UTF-8 decoder.
response.transform(const Utf8Decoder()).join().then(completer.complete);
});
return completer.future;
}
당신은이 같은이 방법/기능을 사용합니다 :
. 그것은 사물을 크게 단순화합니다. –