我的lan中有一个raspberry pi,主机名为'xxx.local‘。我的手机连接到了wifi,但每次我尝试使用'.local‘地址从我的REST后端获取数据时,我都会得到这样的异常:
'SocketException (SocketException:主机查找失败:'xxx.local‘(操作系统错误:没有与主机名关联的地址,错误号= 7))’
但是,当我尝试通过ssh连接到它时,甚至当我尝试使用postman获取数据时,它都工作得很好。
有没有可能跟手机数据有关,因为我的测试手机里面没有SIM卡,所以手机被停用了。如果是,可以不使用sim卡工作吗?
我尝试获取数据的代码:
static Future<List<Device>> fetchDevices() async {
final response = await http.get('http://test-hub.local:9080/devices');
if (response.statusCode == 200) {
final data = json.decode(response.body);
print(data);
List<Device> responses =
data.map<Device>((j) => Device.fromJson(j)).toList();
print(responses);
return responses;
} else {
throw Exception(
'Failed to load Devices: ${response.statusCode} [${response.reasonPhrase}]');
}
}发布于 2021-09-17 13:31:03
我被困在这个问题上很长时间了,问题是Android currently does not support mdns lookups (.local)。
我不知道你是如何获得你的mdns地址的,但是对于使用multicast_dns包的人来说,你可以按照here的描述来获取ip地址。然后,您可以使用该IP地址进行http查询
https://stackoverflow.com/questions/64970012
复制相似问题