「Flutter/HttpRequest」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==httpリクエストサンプル== <pre> import 'package:http/http.dart' as http; String _targetUrl = "https://example.com/api/hoge?id=10"; String response_body = await...」) |
(→"[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: Failed host lookup: (OS Error: No address associated with hostname, errno = 7)"エラーが出た場合) |
||
| (同じ利用者による、間の2版が非表示) | |||
| 行2: | 行2: | ||
<pre> | <pre> | ||
import 'package:http/http.dart' as http; | import 'package:http/http.dart' as http; | ||
| − | String _targetUrl = " | + | String _targetUrl = "ttps://example.com/api/hoge?id=10"; |
String response_body = await http.read(_targetUrl); | String response_body = await http.read(_targetUrl); | ||
</pre> | </pre> | ||
| + | |||
| + | ==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 | ||
| + | <pre> | ||
| + | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| + | package="com.example.hogehoge"> | ||
| + | + <uses-permission android:name="android.permission.INTERNET" /> | ||
| + | <application | ||
| + | </pre> | ||
| + | |||
| + | シミュレータであれば、wifiなど繋がってるか確認。 | ||
2020年1月5日 (日) 23:28時点における最新版
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
シミュレータであれば、wifiなど繋がってるか確認。
