我正在寻找一个简单的Flutter的例子,一个提升的按钮(onPressed)http请求打开硬编码的网址。我不需要响应。我不需要浏览器窗口出现。目标操作系统是Android。提前感谢。UPD:我不需要任何输出。只需要打开如https://autoremotejoaomgcd.appspot.com/sendmessage?key=SECRET_KEY&message=test的网址触发任务(安卓应用程序)任务。
溶液:
import 'package:http/http.dart' as http;
The button:
Expanded(child: ElevatedButton(child: const Text('Flashlight on'), onPressed: () {const url = 'https://autoremotejoaomgcd.appspot.com/sendmessage?key=SECRET_KEY&message=flashlight%20on';_launchHTTP(url);},),)
The function:
void _launchHTTP(String url) async {
var response = await http.get(Uri.parse(url));
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}
2条答案
按热度按时间2nbm6dog1#
日志消息中有什么?您确定HTTP predicate 正确吗?可能此端点需要POST消息?
l2osamch2#