Cordova 10 无法 post ajax 到 http url

Cordova 10 unable to post ajax to http url

我试图将 json 数据发送到 http url 但没有成功(我试图将相同的数据发送到另一个 https 并成功)。 我有这个设置: config.xml

<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

AndroidManifest.xml

android:usesCleartextTraffic="true"

HTML Header

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; img-src * data: 'unsafe-inline'; connect-src * 'unsafe-inline'; frame-src *;"> 
<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready file:; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *">

<script>
  $.ajax({
    type: "GET",
    url: url,
    dataType: "jsonp",
    jsonp: 'callback',
    crossDomain: true,
    async: true,
    data: {
      id: results.rows.item(i).id,
      bolla: results.rows.item(i).bolla,
      anno: results.rows.item(i).anno,
      magazzino: results.rows.item(i).magazzino,
      articolo: results.rows.item(i).articolo,
      quantita: results.rows.item(i).quantita,
      term: terminale
    },
    success: function (data) {
      console.log(data)
    },
    error: function (xhr, textStatus, err) {
      alert("readyState: " + xhr.readyState);
      alert("responseText: " + xhr.responseText);
      alert("status: " + xhr.status);
      alert("text status: " + textStatus);
      alert("error: " + err);
    }
  });
</script>

如果我使用 json 它 returns devicereadystate=0 如果我使用 jsonp 它会出错 returns devicereadystate=4错误 404(url 是正确的,如果我粘贴到它可以工作的浏览器)

我相信这是因为使用 cordova-android 10.0.x,webview 现在充当 https 页面,您不能 load/send 到非安全来源,同时使用 https.

来自 cordova 文档

By default, the WebViewAssetLoader is enabled and allows apps to serve their content from a 'proper' origin. This will makes routing work easily for frameworks like Angular.

With no additional configurations, the app content is served from https://localhost/. You can configure the hostname by setting the preference option hostname.

   <preference name="hostname" value="localhost" />

The scheme, https, is not configurable by nature.