gpt4 book ai didi

android - Http 请求在 Flutter 中不返回任何内容,也不会抛出任何错误

转载 作者:行者123 更新时间:2023-12-05 00:04:48 25 4
gpt4 key购买 nike

使用简单的默认 http 库,这真的让我很困惑。 Http 请求永远不会返回,也不会抛出任何错误。

医生日志如下:

[√] Flutter (Channel master, 1.19.0-2.0.pre.34, on Microsoft Windows [Version 10.0.18362.836], locale en-US)
• Flutter version 1.19.0-2.0.pre.34 at E:\FlutterSDK
• Framework revision 610dc170d9 (3 days ago), 2020-05-14 00:37:02 +0800
• Engine revision b59e3e9c39
• Dart version 2.9.0 (build 2.9.0-8.0.dev 2bf3259005)


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at E:\AndroidSDK
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = E:\AndroidSDK
• Java binary at: E:\android-studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Android Studio (version 3.5)
• Android Studio at E:\android-studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

这是代码:
clockIn(String number, String name, String company, String coords) async {
print(uri);

// var response = await http.post(uri, body: {
// 'Employee_Number': number,
// 'Employee_Name': name,
// 'Company_Name': company,
// 'Coords_In': coords,
// 'Type': 'IN'
// });

var response = await http.get("https://google.com");

final statusCode = response.statusCode;
print('Response Status code: $statusCode');
}

我也尝试过 try-catch ,但没有任何返回。任何地方也没有任何错误。真的让我很困惑。我在 AVD 以及我自己的设备上进行了尝试。

这里是它的名字:
onPressed: () {
if (!isActivated) return;
getEmployeeData().then((value) async {
Position pos = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.best);

clockIn(value[0], value[1], value[2],
"${pos.latitude}, ${pos.longitude}");
});
}

最佳答案

我认为这是因为谷歌,我尝试了不同网址的代码,例如它得到了响应;

clockIn() async {
print("uri");
var myUrl = 'https://www.msn.com';
var response = await http.get(myUrl);
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
}

关于android - Http 请求在 Flutter 中不返回任何内容,也不会抛出任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61836926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com