HTTP调用404?

时间:2018-05-21 14:34:09

标签: android angular rest ionic3

我在访问Magento 2网站时遇到大多数API调用问题,并且一直向Android设备返回404错误。

使用Ionic Serve和Postman时,我对这些API调用没有任何问题。

ionic.config.json

{
  "name": "appname",
  "app_id": "f82ad91b",
  "integrations": {
    "cordova": {}
  },
  "type": "ionic-angular",
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "https://{url}/index.php/rest/V1"
    }
  ]
}

在我的提供商中,我会相应地将路径切换到设备:

提供商/富/ bar.ts

private apiUrl:string;

/**
 * @public
 * @constructor
 */
constructor(
    public http: HttpClient,
    public platform: Platform,
    public storage: Storage,
    private authProvider: AuthenticateProvider,
    private catalogProvider: CatalogProvider) {

    if(this.platform.is('core') || this.platform.is('mobileweb')){
        this.apiUrl = '/api';
    } else {
        this.apiUrl = 'https://{url}/index.php/rest/V1';    
    }
}

config.xml中

<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:*" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />

更新 - 2018-05-23

  • 我注意到错误消息的一件事是这些404错误给了我一个看起来像503错误页面的HTML响应。

  • 注意到在响应标头中,使用Chromes检查工具,错误的响应也添加了content-security-policy: upgrade-insecure-requests。我使用HTTPS网址发送请求,服务器端是HTTPS。不确定这是怎么回事。

更新 - 2018-05-24

  • 尽管我必须使用UIWebView,但iOS构建仍然有效,但该细节与此问题无关。

  • 在index.html文件中添加了一个CSP标记,但未对Android应用进行任何更改。

0 个答案:

没有答案