[Flutter]「Insecure HTTP is not allowed by platform」の対処法

このページには広告が含まれる場合があります。

 

FlutterでWeb通信(http通信)するためのパッケージである「chopper」あるいは「http」を使って、通信を行おうとすると、

Insecure HTTP is not allowed by platform

というエラーが出て処理が中断してしまうことがあります。

なんじゃこれ!?という感じですが、これはFlutterの公式サイトで説明がありまして、

結論から言うと、アクセスしようとしたアドレスの先頭を「http」ではなく「https」にすれば解決するようです。

アドレスが「https」で始まる場合は、通信が暗号化されているため「安全(=セキュア)」である一方、「http」で始まる場合は暗号化されていないため「安全でない(=インセキュア(Insecure)」と判断されるので、そのような通信はAndroid及びiOSでは拒否されてしまうことによるものだそうです。

Starting with Android API 28 and iOS 9, these platforms disable insecure HTTP connections by default.

With this change Flutter also disables insecure connections on mobile platforms. Other platforms (desktop, web, etc) are not affected.

You can override this behavior by following the platform-specific guidelines to define a domain-specific network policy. See the migration guide below for details.

Much like the platforms, the application can still open insecure socket connections. Flutter does not enforce any policy at socket level; you would be responsible for securing the connection.

下の動画の例で言うと、アクセスに使っていたアドレスが

https://newsapi.org/v2

になっていたので、

https://newsapi.org/v2

に変えるとうまくいきました。

(詳しくは、以下の動画で解説していますので、よろしければご覧下さい)

こんな記事も読まれています

人気No.1

前向きな気持ちになれる 占星術・タロットリーディング

あすコロ式・相談サロン 【ナビるやん】

人に言えない悩みから使命・運勢診断まで、あなたに寄り添いながら“ナビゲート”する、あすコロ人気No.1のオンライン相談サロン。占星術・心理学・タロットの叡智を活かし、普段認識していない「潜在意識」にアクセスしてあなたの気づいていない可能性を拓かせ、明日から前向きに歩めるようになる60分のリーディングセッション。

今すぐ詳細を見る(メルマガ登録で初回半額) ▶

TOP