【发布时间】:2018-05-02 12:35:05
【问题描述】:
我正在关注Flutter Networking/HTTP tutorial 向在我的 localhost:8000 上运行的服务器发出 GET 请求。通过我的浏览器访问我的本地主机工作正常。我的代码如下所示:
var url = 'http://localhost:8000';
Future<String> getUnits(String category) async {
var response = await httpClient.get('$url/$category');
return response.body;
}
当我指向任何真实的 URL(例如 https://example.com)时,这可以正常工作,但是当我指向 https://localhost:8000 或 https://localhost(或这些的任何变体)时,我会收到以下开头的错误:
E/flutter ( 4879): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 4879): SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 47060
E/flutter ( 4879): #0 IOClient.send (package:http/src/io_client.dart:30:23)
每次我重新加载应用程序时,上述错误中的端口都会更改。我查看了http package code,似乎没有办法为 URL 指定端口。如何指向我的本地主机?
【问题讨论】:
-
对于在 iis/express 上遇到此问题的任何人,请检查:stackoverflow.com/questions/58367151/…
标签: http dart localhost flutter