How to Solve ’Insecure HTTP is not allowed by platform’ Error

Are you getting "Insecure HTTP is not allowed by platform" or "Unhandled Exception: DioError [DioErrorType.other]: Bad state: Insecure HTTP is not allowed by platform: http://" while running your Flutter APP.  This is caused by insecure "HTTP" or insecure Websocket "WS" protocol. Your REAT API request or Websocket connection to the server may not be working due to this error.

E/flutter (31725): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 
DioError [DioErrorType.other]: Bad state: Insecure HTTP is not allowed by 
platform: http://192.168.0.109/kpl/api/api_login.php?auth=rabidfgjsdfjgk435439jkfdj
E/flutter (31725): #0      _HttpClient._openUrl (dart:_http/http_impl.dart:2434:7)
E/flutter (31725): #1      _HttpClient.openUrl (dart:_http/http_impl.dart:2341:7)

To solve this issue, either you should use a secure "HTTPS" protocol during web requests and secure Websocket "WSS" protocol. Use "https://" instead of "HTTP://" and use "wss://" instead of "ws://".

If you don't want to use the secure protocol, then you should allow an Insecure protocol request to the web or REST API. To allow insecure HTTP or WS protocol, follow the following steps. 

 Issue on Android:

Add android:usesCleartextTraffic="true" attribute on <application> tag in \android\app\src\debug\AndroidManifest.xml:

<application android:usesCleartextTraffic="true"/>

This attribute allows insecure HTTP requests and insecure WebSocket connection on your Flutter app.

For iOS, create Info--debug.plist file and put this in the file:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Buy putting few lines on the configuration file of your Flutter app may solve the "Insecure HTTP" issue in your Android and iOS app.

No any Comments on this Article


Please Wait...