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

Solution 1: thedarthcoder

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.

Solution 2: LMM

Change localhost with

Solution 3: reket Torres

try to enable cross origin in spring boot in rest controller class( it works for me)

@CrossOrigin(origins = {"http://localhost:4200", ""})
public class UsuarioClienteRestController {......}

"http://localhost:4200" for angular(web)

"" for flutter