vscode中出现CERTIFICATE_VERIFY_FAILED握手错误,但在Android Studio中运行正常

3okqufwl  于 2023-02-09  发布在  Android
关注(0)|答案(1)|浏览(227)

我是flutter新手,我的flutter环境已经设置好了。我使用VS代码作为我的编辑器。当我试图请求apis时,它把我扔了
HandshakeException: Handshake error in client
最后我在网上搜索了一下,找到了解决办法

void main() {
  HttpOverrides.global = MyHttpOverrides();
  runApp(const MyApp());
}

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

它完成了这项工作,但有人提到,这并不理想。(特别是对生产。)
几天后,我尝试使用Android Studio进行一个新项目,发现在Android Studio上请求API没有问题。我以为错误已修复,但当我在VS代码上运行完全相同的代码时,再次出现握手错误。
我真的很想使用VSCode,因为它真的很轻的使用。
那么,有谁能帮我一下,是什么导致了VS代码的这个问题,为什么完全相同的代码在Android Studio上工作?
以下是flutter doctor -v的输出

[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale
    en-IN)
    • Flutter version 3.3.10 on channel stable at
      /Users/dev.meena/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (8 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/dev.meena/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Users/dev.meena/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/dev.meena/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/dev.meena/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Community Edition (version 2022.3.1)
    • IntelliJ at /Users/dev.meena/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/223.8214.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.74.2)
    • VS Code at /Users/dev.meena/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • B401E3BC-F514-4C34-B73F-B9B31B70C5E8 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.1 22C65 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

我希望这两种环境的工作方式相似。

lzfw57am

lzfw57am1#

我建议你先用posman或nommy运行API,如果你有证书错误,请联系后台人员,因为这是一个糟糕的服务器配置

相关问题