JoshuaaMarkk
JoshuaaMarkk

Reputation: 123

Flutter desktop App not being able to connect to localhost. Flutter/Dart

I am trying to connect to my localhost:8080 through my Flutter desktop app, but I am receiving this error

"Unhandled Exception: The remote computer refused the network connection."

this is my code :

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''',
  );

}

Any solution would be greatly appreciated.

Upvotes: 0

Views: 359

Answers (1)

Rakesh Saini
Rakesh Saini

Reputation: 763

Instead using the 'localhost' you have to use your system's IP address like.

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

You can get the system's IP address by typing the 'ipconfig ' in command prompt.

Upvotes: 0

Related Questions