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)
...
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)
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With