我正在制作一个应用程序,并且我已经在本地运行服务器。我可以向导航员发送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的主机或在我的flutter或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
答案 0 :(得分:3)
您的PC上的本地主机与Android模拟器上的本地主机不同。要从Android模拟器访问PC的本地主机,您需要指向10.0.2.2
。
这意味着您需要将代码更改为:
String url = 'http://10.0.2.2:4444/categorie?page_size=15&page=1';
答案 1 :(得分:3)
在"C:\VS2019\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\dumpbin.exe" /DEPENDENTS ImageComprehensionCOM.dll
Microsoft (R) COFF/PE Dumper Version 14.24.28314.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file ImageTestCOM.dll
File Type: DLL
Image has the following dependencies:
ippi-8.0.dll
ipps-8.0.dll
ippcv-8.0.dll
opencv_core2410.dll
opencv_imgproc2410.dll
opencv_highgui2410.dll
mfc140.dll
KERNEL32.dll
USER32.dll
ADVAPI32.dll
ole32.dll
OLEAUT32.dll
MSVCP140.dll
VCRUNTIME140.dll
VCRUNTIME140_1.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-utility-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-multibyte-l1-1-0.dll
Summary
25000 .data
文件中的依赖关系下使用它:
LoadLibrary
将此方法用于Http请求
pubspec
模型类:
http: ^0.12.0+2