First, you need to make sure that you have enabled the data switch in the quick settings panel.
Enter the following code line by line, do not enter two lines at once.
Android 11
adb shell settings put global captive_portal_mode 0
adb shell settings put global captive_portal_https_url https://www.google.cn/generate_204
Android 10 - Android 7.1.1
adb shell settings put global captive_portal_https_url https://www.google.cn/generate_204
Android 7.1 & Android 7.0
adb shell settings delete global captive_portal_server
adb shell settings put global captive_portal_detection_enabled 0