简体   繁体   English

Dart/Flutter 使用 HTTP 连接 Springboot api

[英]Dart/Flutter using HTTP to connect to Springboot api

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我正在使用 http(dart 包)连接到本地部署的 springboot api,但是,应用程序抛出连接拒绝错误 111 并显示错误的端口

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.尝试打开端口以查看是否有帮助,将本地主机替换为计算机 ipm 更改了 springboots 端口,但问题仍然存在。

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

使用 10.0.2.2 更改 localhost。

Try turning off your server machine firewall or add an exception for the IP address inside your antivirus program.尝试关闭服务器计算机防火墙或为防病毒程序中的 IP 地址添加例外。 Also if you're using subnet IP address then make sure your server machine and mobile device are connected to the same network.此外,如果您使用子网 IP 地址,请确保您的服务器计算机和移动设备连接到同一网络。

try to enable cross origin in spring boot in rest controller class( it works for me)尝试在rest控制器类中的spring boot中启用cross origin(它对我有用)

@CrossOrigin(origins = {"http://localhost:4200", "http://10.0.2.2:8080"})
@RestController
@RequestMapping("/api")
public class UsuarioClienteRestController {......}

"http://localhost:4200" for angular(web) “http://localhost:4200”用于角度(网络)

"http://10.0.2.2:8080" for flutter “http://10.0.2.2:8080”用于颤动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM