1
0

More than 1 year has passed since last update.

[Flutter] MacOSで_ClientSocketException: Connection faild が出たときの対応

Last updated at Posted at 2022-10-16

経緯

Flutterアプリを作る際に、
サンプルを参考にしながら
APIからJSONの値を取得して、その値をそのまま表示するサンプルを作るときに躓きました。

内容

package:http/http.dart を使って get をすると以下のようなエラーが出ました。

_ClientSocketException (Connection failed)

Exceptionの内容は以下の通り。(xxx.comは仮)

Exception has occurred.
SocketException (SocketException: Connection failed (OS Error: Operation not permitted, errno = 1), address = xxxx.com, port = 443)

対応

FlutterのMacOSアプリセッティング記載がありまして、
アプリからネットワークのリクエストを投げるには
com.apple.security.network.clientのentitlementsを追加する必要があるようでした。

そのため、対応としては
macos/Runner/DebugProfile.entitlements
ファイルの要素内に以下を追加することで解決。

macos/Runner/DebugProfile.entitlements
    <key>com.apple.security.network.client</key>
    <true/>

やっとデータが取れた。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0