jeudi 25 mars 2021

How can i make local http request in flutter?

when i make access on website on endpoint "http://localhost/newsapp_api/public/api/authors"it's work without any problem,but when i try this in flutter it shows me a problem. message error:E/flutter (24506): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 46873 codes:

authors_api.dart

import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:news_app/utilities/api_utilities.dart';

import 'package:news_app/models/author.dart';

class AuthorsAPI {

  Future<List<Author>> fetchAllAuthors() async {
    // ignore: deprecated_member_use
    List<Author> authors = List<Author>();
    String allAuthorsApi = base_api + all_authors_api;
    var url = Uri.parse(allAuthorsApi);

    var response = await http.get(url);
    print(response.statusCode);
    print("*****************");
    print(response.body);
  }
}

api_utilities.dart

String base_api = "http://localhost/newsapp_api/public/api/authors";
String all_authors_api = "/api/authors";


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire