skip to Main Content

i am using the following code to send http request to my django localhost site:

var url = Uri.http('127.0.0.1:8008', '/apis/login', 
                    {'q':'{http}',
                    'phone': userName, 'password': password});
var response = await get(url);
var myResponse = jsonDecode(response.body);
print(myResponse);

but it raised this error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 38598, uri=http://127.0.0.1:8008/apis/login?q=%7Bhttp%7D&phone=dslfkslf&password=rrrrrrrrrrrrrrC%3A%5CUsers%5Cgeors%5CAppData%5CLocal%5CPub%5CCache%5Clog%5Cpub_log.txt

E/flutter ( 4683): #0 IOClient.send (package:http/src/io_client.dart:154:7)

2

Answers


  1. If you are trying to access the api on your mobile device it will not work. you will have to enter the IP address of the your local machine and replace 127.0.0.1:8008 with ip-address:8008

    Login or Signup to reply.
  2. If you using emulator, Use 10.0.2.2 to access your actual machine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search