gpt4 book ai didi

android - $.ajax POST 返回 "status":403 ,"statusText" :"Forbidden" cordova android

转载 作者:行者123 更新时间:2023-11-29 20:53:46 26 4
gpt4 key购买 nike

我正在使用 jquery.mobile-1.4.3.js 和 cordova.3.5.0 开发 Android phonegap 应用程序。

我正在为 Web 服务调用 $ajax。下面是一个代码 fragment 。

 $.ajax({
type: 'POST',
data: LoginData,
crossDomain:true,
dataType : 'json',
timeout: 50000,
url: 'https://dsp-wasatchtechies.cloud.dreamfactory.com/rest/user/session?app_name=XXXXX',
success: function(data) {


console.log(' SESSION' + JSON.stringify(data));

},
error: function(data) {

//ActivityIndicator.hide();
console.log('ERROR : SESSION' + JSON.stringify(data));
//ShowAlertMessage('There was an error while SESSION');
}
});

它工作得很好,但现在它的响应:

  [INFO:CONSOLE(155)] "ERROR SESSION{"readyState":4,"responseText":"","status":403,"statusText":"Forbidden"}", source: file:///android_asset/www/js/index.js (155)

这段代码有什么问题?为什么它不起作用?任何帮助,建议将不胜感激

提前致谢。

最佳答案

  1. 确保服务器代码返回 CORS header 以授予来自其他站点的访问权限:

eg: header('Access-Control-Allow-Origin: *');

  1. 确保“ModSecurity”在您的服务器上被禁用(如果您有 cPanel 访问权限,您应该能够通过 cPanel/Security 或类似的东西做到这一点)

  2. 确保安装了 cordova 白名单插件(使用 cordova pre v5.0.0 的“legacy”插件):

    $ cordova 插件添加 cordova-plugin-legacy-whitelist

  3. 在你的 cordova config.xml 中设置一个非常开放的白名单:

  4. 在您的 index.html 中设置内容安全策略:

    <meta http-equiv="Content-Security-Policy"content="default-src *; script-src * 'unsafe-eval' 'unsafe-inline'; connect-src *; img-src *; 样式-src * 'unsafe-inline' ; media-src *;">

这使得一切都 WIDE 开放,而跨源域、白名单 URL 请求和内容安全策略的要点是限制跨域访问。在您使它正常工作之后,我将把它留作研究和限制安全性的练习。

希望对您有所帮助。

引用资料:

https://github.com/apache/cordova-plugin-whitelist#content-security-policy https://cordova.apache.org/announcements/2015/04/21/plugins-release-and-move-to-npm.html http://content-security-policy.com/

关于android - $.ajax POST 返回 "status":403 ,"statusText" :"Forbidden" cordova android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28338435/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com