
[英]Mapping a class to json while calling an Api showing error in flutter
[英]connection failed while calling api in flutter
我正在使用 swagger 连接 api 它给出了极好的结果但是当通过移动应用程序点击 api 时它抛出错误connection failed: OS Error: Network is unreachable errorno= 101
我的 api 调用代码
var file = await File(filepath).readAsBytes();
var uri = Uri.parse('http://192.168.18.2:1111/predict');
// print(url);
// Create a multipart request
var request = http.MultipartRequest("POST", uri);
// Create a multipart file
var multipartFile = http.MultipartFile.fromBytes(
'file',
file,
filename: filepath.split("/").last,
);
// Add the file to the request
request.files.add(multipartFile);
try{
return await request.send();
}
catch(e){
return http.StreamedResponse(Stream.error(e), 404);
}
这可能是由于许多问题。
如果您使用 HTTP 而不是 HTTPS,则在 android 和 iOS 上,您必须允许在 Android 8 或更高版本上使用明文。
最好的起点是在执行代码时查看logcat ,这将了解导致失败的原因。 如果您从模拟器连接到本地计算机,则还需要改用10.0.2.2 地址。
如果您在本地网络上从真实设备连接到 PC,请确保您在同一个网络中,防火墙允许您连接等。 以及。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.