Android Studio 抖动http获取请求按钮,不需要响应

2w3kk1z5  于 2023-01-09  发布在  Android
关注(0)|答案(2)|浏览(194)

我正在寻找一个简单的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}');
}
2nbm6dog

2nbm6dog1#

日志消息中有什么?您确定HTTP predicate 正确吗?可能此端点需要POST消息?

l2osamch

l2osamch2#

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 {
await http.get(Uri.parse(url));
}

相关问题