close

[Solved] SocketException: OS Error: Connection refused, errno = 111 in flutter

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track APIs in postman working fine But when I run in App It Give me an error. SocketException: OS Error: Connection refused, errno = 111 in flutter in flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How SocketException: OS Error: Connection refused, errno = 111 Error Occurs ?

I am working on APIs. APIs are working fine in postman. But when I implement it in my flutter app it Gives me SocketException. Here is my code.

      var data = {
            'email':emailcontroller.text,
            'password':passwordcontroller.text,
           };
        await http.post(
                  'localhots:8000/signup,
                  body: json.encode(data)
                       )
          .then((onResponse){
            print(onResponse.body);
          }).catchError((onerror){
            print(onerror.toString());
        });
SocketException: OS Error: Connection refused, errno = 111

How to Solve SocketException: OS Error: Connection refused, errno = 111 Error?

  1. How to Solve SocketException: OS Error: Connection refused, errno = 111 Error?

    to Solve SocketException: OS Error: Connection refused, errno = 111 Error Just Open Your terminal on PC. ( Where Your API Code ). Just type ipconfig. And hit Enter button. Just copy the IPv4 Address from the terminal output. Use that IP address instead of localhost So that your URL may look like 192.168.0.2:8000/signup.

  2. SocketException: OS Error: Connection refused, errno = 111 Error

    to Solve SocketException: OS Error: Connection refused, errno = 111 Error Just Open Your terminal on PC. ( Where Your API Code ). Just type ipconfig. And hit Enter button. Just copy the IPv4 Address from the terminal output. Use that IP address instead of localhost So that your URL may look like 192.168.0.2:8000/signup.

Solution 1

  1. Open Your terminal on PC. ( Where Your API Code ).
  2. Just type ipconfig. And hit Enter button.
  3. Just copy the IPv4 Address from the terminal output.
  4. Use that IP address instead of localhost
  5. So that your URL may look like 192.168.0.2:8000/signup.

Solution 2

If you are not using emulator OR simulator and You are working with real device then make sure Your APIs PC and Your real device Both are connected with same network.

Summery

So, It’s All About SocketException: OS Error: Connection refused, errno = 111 in a flutter. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: