Why i'm getting WRONG_VERSION_NUMBER when making a POST request to a HTTPS Server?

10,416

Solution 1

As @Patrick mentioned in the comments, this is the result of TLS mismatch.

General thumb rule: If the server (API) is based on https (TLS) then the client should connect using https. If the server uses http (non-TLS) then the client should use http to connect to it.

In your case, seems like the API you are trying to hit is an http type hence from your flutter app you should use:

Uri.http(baseUrl, endPointUrl)

Solution 2

I think you are using https:// but havent installed SSL certificate. So try to use http:// instead of https://. This work in my case. hope also work on your side.

Solution 3

Add this to your android/app/src/main/AndroidManifest.xml

android:usesCleartextTraffic="true"

the result is this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.contact_wsp">
   <application
        android:label="contact_wsp"
        android:usesCleartextTraffic="true"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
Share:
10,416
Lucas Pires
Author by

Lucas Pires

Updated on December 13, 2022

Comments

  • Lucas Pires
    Lucas Pires over 1 year

    My app does a lot of HTTP requests to a server. After installing a SSL certificate on it, the app broke.

    My server is running Ubuntu with Nginx hosting PHP code (using the certificate and working) and "proxy-ing" the app server code written in NodeJS. It was working until I changed to HTTPS.

    My POST Request typical usage:

    var jsonRequest = //Some JSON.
    Map<String, String> headers = {'Content-type': 'application/json'};
    var response = await http.post(urls['auth'], body: jsonRequest,headers: headers);
    

    The error I get:

    E/flutter (25875): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error: 
    E/flutter (25875):      WRONG_VERSION_NUMBER(tls_record.cc:242))
    
    E/flutter (25875): #0      IOClient.send (package:http/src/io_client.dart:33:23)
    E/flutter (25875): <asynchronous suspension>
    E/flutter (25875): #1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:169:38)
    E/flutter (25875): <asynchronous suspension>
    E/flutter (25875): #2      BaseClient.post (package:http/src/base_client.dart:54:7)
    E/flutter (25875): #3      post.<anonymous closure> (package:http/http.dart:70:16)
    
    ...