【发布时间】:2020-06-22 22:09:15
【问题描述】:
我正在制作一个应用程序,并且我已经在本地运行了一个服务器。我可以通过导航器访问网址:
Request URL: http://localhost:4444/categorie?page_size=15&page=1
Request Method: GET
Status Code: 200 OK
Remote Address: 127.0.0.1:4444
Referrer Policy: no-referrer-when-downgrade
预览:
{
"count": 4,
"next": null,
"previous": null,
"results": [
{
"uid": "_b656062d3754",
"name": "Pinga"
},
{
"uid": "_0c644473c244",
"name": "Cerveja"
},
{
"uid": "_75df557ccbaa",
"name": "Vinhos"
},
{
"uid": "_8e32ce3baded",
"name": "Refrigerantes"
}
]
}
但是当我尝试颤动时,请求永远不会响应:
getCategories() async {
String url = 'http://localhost:4444/categorie?page_size=15&page=1';
var response = await http.get(url);
if (response.statusCode == 200) {
// If the call to the server was successful, parse the JSON
return response.body;
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}
我正在使用Django 在我的Windows10 中运行服务器。我的颤振应用程序位于Android Studio 中,使用Virtual Machine 作为设备。
我尝试将 ip 更改为 127.0.0.1 和 10.0.0.1 但仍然无法正常工作。我是否更改了 Django 的主机或在我的颤振或 VirutalBox 内部启用任何配置?
- 对其他站点的请求运行良好。问题出在本地。
我的依赖:
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
http: any
dev_dependencies:
flutter_test:
sdk: flutter
【问题讨论】:
-
@ViniciusMorais 我的回答解决了您的问题吗?如果是,请将其标记为正确。
-
不抱歉,我不得不更改我的 Django 配置来解决我的问题并从 url 请求更改 IP。