cordova ios 6.1.0 wkwebview某些xhr POST失败



随着每个人都在使用离子堆栈进行开发,由于苹果的要求,我们也进入了新的wkwebview。

我们已经提供了一个没有任何警告的ios构建(关于uiwebview旧代码(,但在执行某些POST调用时仍然遇到问题。

设置

我们已经设置了如下的cors服务器端(Apache(:

<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>com.hrd.auth.tomcat7.cors.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>app://myapp, http://localhost:9090</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,Accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,User-Agent,DEVICE_ID</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<!-- <init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param> -->
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

下面是当前的应用程序配置:

<description>An app from company S.r.l.</description>
<author email="sviluppo@mycompany.com" href="https://www.mycompany.com/">       Contact us  </author>
<content src="index.html" />
<!-- Permissions -->
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<!-- Preferences -->
<preference name="webviewbounce" value="false" />
<preference name="KeyboardResize" value="false" />
<preference name="BackupWebStorage" value="none" />
<preference name="DisallowOverscroll" value="true" />
<preference name="AutoHideSplashScreen" value="true" />
<preference name="StatusBarStyle" value="lightcontent" />
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="FadeSplashScreenDuration" value="1500" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="KeyboardDisplayRequiresUserAction" value="false"/>
<!-- Hooks -->
<hook src="www/hooks/fwk-after-prepare-hooks.js" type="after_prepare" />
<hook src="www/hooks/fwk-after-plugin-add-hooks.js" type="after_plugin_add" />
<hook src="www/hooks/fwk-after-prepare-copy-build-extra-hooks.js" type="after_prepare" />
<hook src="www/hooks/fwk-after-compile-hooks.js" type="after_compile" />
<hook src="www/hooks/fwk-before-build-hooks.js" type="before_build" />
<!-- iOS -->
<platform name="ios">
<!-- CORS -->
<preference name="scheme" value="app" />
<preference name="iosScheme" value="app" />
<preference name="hostname" value="myapp" />
<!-- Resouces -->
<resource-file src="www/GoogleService-Info.plist" />
<icon height="20" src="www/res/icon/ios/Icon-20.png" width="20" />
...
</platform>

<!-- PLUGINS LIST -->
<!-- LIST -->
<!-- Don't modify this plugins list because it's generate-->
<plugin name="cordova-plugin-app-version" spec="0.1.9"/>
<plugin name="cordova-plugin-calendar" spec="4.6.0"/>
<plugin name="cordova-plugin-call-number" spec="1.0.1"/>
<plugin name="cordova-plugin-camera" spec="4.1.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="Allow_the_app_to_use_your_camera" />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Allow_the_app_to_access_your_photos" />
</plugin>
<plugin name="cordova-plugin-compat" spec="1.2.0"/>
<plugin name="cordova-plugin-device" spec="1.1.7"/>
<plugin name="cordova-plugin-facebook4" spec="6.2.0">
<variable name="APP_ID" value="2553981324652029" />
<variable name="APP_NAME" value="com.mycompany.myapp" />
</plugin>
<plugin name="cordova-plugin-file" spec="6.0.2"/>
<plugin name="cordova-plugin-inappbrowser" spec="4.0.0"/>
<plugin name="cordova-plugin-ionic-keyboard" spec="2.2.0"/>
<plugin name="cordova-plugin-media-capture" spec="3.0.3">
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Allow_the_app_to_access_your_photos" />
</plugin>
<plugin name="cordova-plugin-network-information" spec="1.3.4"/>
<plugin name="cordova-plugin-splashscreen" spec="5.0.3"/>
<plugin name="cordova-plugin-statusbar" spec="2.4.2"/>
<plugin name="cordova-plugin-whitelist" spec="1.3.3"/>
<plugin name="cordova-plugin-sign-in-with-apple" spec="0.1.0"/>
<plugin name="cordova-plugin-wkwebview-inject-cookie" spec="1.0.6"/>
<engine name="ios" spec="6.1.0" />

问题

应用程序执行成功的POST登录调用,并提供以下xhr详细信息

"{"method":"POST",
"post":"{
\"username\":\"username\",
\"password\":\"password\"
}",
"url":"http://192.168.1.129:8080/go/rest/security/appLogin/MY_APP_LOGIN",
"headers":{"Content-Type":"application/json",
"DEVICE_ID":"a91d602c140079f2e848f39e33a6ca88",
"Accept":"application/json,text/plain,*/*"},
"withCredentials":true}"

但是,在这个调用中(在经过身份验证后执行(,正在失败:

"{"method":"POST",
"post":"{
\"test\":\"test\"
}",
"url":"http://192.168.1.129:8080/go/rest/security/userInfo",
"headers":{
"Accept":"application/json,text/plain,*/*",
"Content-Type":"application/json;charset=utf-8"
},
"withCredentials":true}"

环境配置

  • 包含以下堆栈的离子束**ionic.js 1.3.2**angularJS 1.5.3
  • cordova 9.0.0
  • cordova ios 6.1.0

有人知道为什么这种呼叫失败吗?

常见问题

  1. 与第一个(登录调用(不同,第二个没有到达服务器CorsFilter.java类,所以调用"不退出APP">
  2. 与移动环境不同,我们的小部件环境已经修复了POST调用,只是将调用负载模拟数据放入其中,以抱怨w3c浏览器规范

非常感谢Simone

我们发现了调用无法到达服务器CorsFilters.java类的问题(因此不可能获得一些调试实例(。

阅读我们的服务器日志,我们发现了这一行

192.168.x.x - - [02/Sep/2020:17:40:09 +0200] "OPTIONS /go/rest/security/userInfo HTTP/1.1" 401 7361 4286

这是关于飞行前POST请求的一个众所周知的问题,所以我们只需在web.xml conf.文件中添加以下属性

<web-resource-collection>
<web-resource-name>REST</web-resource-name>
<description>REST services</description>
<url-pattern>/rest/*</url-pattern>
<http-method-omission>OPTIONS</http-method-omission> <<--- add this row
</web-resource-collection>

这样,所有OPTIONS请求都将被接受,而不是被拒绝!

希望这能帮助头痛数周的人;(

Simon

相关内容

  • 没有找到相关文章

最新更新