Я делаю приложение, и у меня уже есть сервер, работающий на моем локальном компьютере. Я могу обратиться к своему навигатору по URL:
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');
}
}
Я использую сервер в моем Windows10
, используя Django
. И мое приложение флаттера в 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