为什么印前检查在较新的 Android 设备上失败,但在旧设备和台式机上却没有?

Why does preflight fail on newer Android devices but not older devices and desktop?

(这是使用 Chrome 的远程设备功能来检查来自应用程序的请求)

return [
    'paths' => ['*'],
    'allowed_methods' => ['*'],
    'allowed_origins' => ['*'],
    'allowed_origins_patterns' => [],
    'allowed_headers' => ['*'],
    'exposed_headers' => [],
    'max_age' => 0,
    'supports_credentials' => false,
];

该问题与 SSL/TLS 固定有关,而 axios 并未按照 this comment 进行处理。

The Ionic Native HTTP plugin 本机处理固定并且适用于但当然它利用了非移动设备上不可用的 Cordova。

有两种可能的解决方案:

  1. 实现 SSL/TLS 本机固定
  2. 创建一个service/factory决定我们是要使用axios还是原生插件

我选择了 #2 - 如果您需要有关 #1 的信息。

我使用以下方法确定使用哪个 HTTP 包装器:

static makeRequest() {
    return isPlatform('cordova') ? cordovaHttpService : axiosHttpService;
}

当然,可以根据具体情况进行修改。