2

I want to post data to the server with dio library but when I send data, I get XMLHttpRequest error. The server programmer checked twice his codes and made sure to enable CORS in the server. I think this error occurs because the server is not HTTPS and the browser blocks the request. I use this code to send my data to the server:

Response response = await client
        .post(theUrl,
            options: Options(
                validateStatus: (status) {
                  return status! < 500;
                },
                followRedirects: false,
                headers: {
                  HttpHeaders.contentTypeHeader: "application/json",
                  HttpHeaders.acceptHeader: "*/*",
                  HttpHeaders.accessControlAllowOriginHeader:
                      "Access-Control-Allow-Origin, Accept",
                }),
            data: convert.json.encode(data))
        .timeout(const Duration(seconds: 10));

My log is just:

DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.

So, How can I ignore the certificate of the server host and send data to an HTTP URL in flutter web?

Marlen Schreiner
  • 726
  • 10
  • 25

1 Answers1

0

I'm almost sure that the problem is because your server doesn't have an https certificate. A workaround is run / debug your application with flutter desktop.

You can also take a look at: How to solve flutter web api cors error only with dart code?

Will
  • 445
  • 2
  • 12