「Flutter/HttpRequest」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行8: | 行8: | ||
==urlエンコード== | ==urlエンコード== | ||
"ttp://example.com/api/hoge?body=" + Uri.encodeComponent("本文1") | "ttp://example.com/api/hoge?body=" + Uri.encodeComponent("本文1") | ||
| + | |||
| + | =="[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: Failed host lookup: (OS Error: No address associated with hostname, errno = 7)"エラーが出た場合== | ||
| + | Androidの場合 | ||
| + | |||
| + | 以下を追加 | ||
| + | |||
| + | android/app/src/main/AndroidManifest.xml | ||
| + | <pre> | ||
| + | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| + | package="com.example.hogehoge"> | ||
| + | + <uses-permission android:name="android.permission.INTERNET" /> | ||
| + | <application | ||
| + | </pre> | ||
2019年12月31日 (火) 03:35時点における版
httpリクエストサンプル
import 'package:http/http.dart' as http; String _targetUrl = "ttps://example.com/api/hoge?id=10"; String response_body = await http.read(_targetUrl);
urlエンコード
"ttp://example.com/api/hoge?body=" + Uri.encodeComponent("本文1")
"[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: Failed host lookup: (OS Error: No address associated with hostname, errno = 7)"エラーが出た場合
Androidの場合
以下を追加
android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hogehoge">
+ <uses-permission android:name="android.permission.INTERNET" />
<application
