Dart/Flutter using HTTP to connect to Springboot a

2019-08-28 00:09发布

问题:

I'm using http (dart package) to connect to a locally deployed springboot api, However, the application throws Connection refused error 111 and shows the wrong port

Tried opening the port to see if that helped, replaced local host with the computers ipm changed springboots port but the problem is still there.

The line that connects to the server

final response = await http.get('http://localhost:8080/api/v1/alltables');

console log error:

ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (27342): SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 49588

回答1:

Try turning off your server machine firewall or add an exception for the IP address inside your antivirus program. Also if you're using subnet IP address then make sure your server machine and mobile device are connected to the same network.



回答2:

Change localhost with 10.0.2.2.