Flutter web http Error: XMLHttpRequest error.

2,228 views
Skip to first unread message

Sulejman Limaj

unread,
Dec 1, 2021, 3:12:41 AM12/1/21
to Flutter Development (flutter-dev)
Hello everyone, 

I've been struggling with an http request issue when I try to perform a simple post request to a .net backend. The backend has CORS set up and I've been through many stack overflow posts, trying to solve this issue but it still gives me the same error. 

The code: 

import 'dart:convert';
import 'package:http/http.dart' as http;

abstract class ParentRemoteDataSource {
  Future<void> create({required Map<String, dynamic> parent});
}

class ParentRemoteDataSourceImpl implements ParentRemoteDataSource {
  final http.Client _client = http.Client();
  final String _url = "http://localhost:5000/api/member/create";

  @override
  Future<void> create({required Map<String, dynamic> parent}) async {
    final Uri uri = Uri.parse(_url);
    final Map<String, String> headers = {"Content-Type": "application/json"};

    final http.Response response = await _client.post(
      uri,
      headers: headers,
      body: jsonEncode(parent),
    );
    print(response.body);
  }
}

The code above executes at the press of a button on the UI part.
The error from the post request reads: ERR_CERT_AUTHORITY_INVALID
And below that reads: Uncaught (in promise) Error: XMLHttpRequest error.
There is a screenshot in the attachment. I appreciate any help I can get from the community. Thank you. 

2021-12-01 (3).png
Reply all
Reply to author
Forward
0 new messages