【问题标题】:Flutter desktop App not being able to connect to localhost. Flutter/DartFlutter 桌面应用程序无法连接到本地主机。颤振/飞镖
【发布时间】:2023-02-24 13:33:01
【问题描述】:

我正在尝试通过我的 Flutter 桌面应用程序连接到我的 localhost:8080,但我收到此错误

“未处理的异常:远程计算机拒绝网络连接。”

这是我的代码:

class LoginRequestCall {
  static Future<ApiCallResponse> call({
    String? userName = '',
    String? password = '',
  }) {
    return ApiManager.instance.makeApiCall(
      callName: 'loginRequest',
      apiUrl: 'http://localhost:8080/HongLeong/LOGIN_REQUEST.do',
      callType: ApiCallType.POST,
      headers: {},
      params: {
        'UserName': userName,
        'Password': password,
      },
      bodyType: BodyType.X_WWW_FORM_URL_ENCODED,
      returnBody: true,
    );
  }

  static dynamic messageID(dynamic response) => getJsonField(
    response,
    r'''$.RESPONSE.BASEL_RESPONSE.ErrEntity.MessageID''',
  );
  static dynamic userName(dynamic response) => getJsonField(
    response,
    r'''$.RESPONSE.BASEL_RESPONSE.UserName''',
  );
  static dynamic serverName(dynamic response) => getJsonField(
    response,
    r'''$.RESPONSE.RESPONSE_HEADER.server_name''',
  );

}

任何解决方案将不胜感激。

【问题讨论】:

    标签: flutter api dart networking localhost


    【解决方案1】:

    而不是使用“本地主机”,您必须使用系统的 IP 地址。

    "http://3.93.240.49:8080/HongLeong/LOGIN_REQUEST.do"
    

    您可以通过在命令提示符中键入“ipconfig”来获取系统的 IP 地址。

    【讨论】:

    • 恐怕它仍然不起作用,我试过使用“以太网适配器以太网”中的 ipv4。
    猜你喜欢
    • 2019-11-21
    • 1970-01-01
    • 2020-04-24
    • 2017-11-26
    • 2020-07-05
    • 1970-01-01
    • 2022-06-20
    • 2021-03-11
    • 1970-01-01
    相关资源
    最近更新 更多