【问题标题】:ionic2: ios simulator error: Response with status: 0 for URL: nullionic2:ios 模拟器错误:响应状态:0 对于 URL:null
【发布时间】:2018-06-11 11:07:36
【问题描述】:

我正在使用 ionic2:我的应用程序使用 Web 服务 API,它在浏览器中正常工作,因为我在浏览器中启用了 cors origin plugin,但我将它运行到 ios 模拟器我有这个错误:Response with status: 0 for URL: null 在我的所有 api服务方法我附加这样的标题:

addPost(token, image, description) {
    var headers = new Headers();
    headers.append('Content-Type', 'applocation/json');
    headers.append('Access-Control-Allow-Origin', '*');

    let postObject = {
        "token": token,
        "image": image,
        "description": description,
    }
    console.log("from service "+ postObject.description);
    console.log("from service "+ postObject.image);
    return this.http.post(this.addPostUrl,postObject,{headers:headers})
    .map((response: Response) => response.json())
}

我尝试发送这样的标题:

let headers = new Headers( {
        'Access-Control-Allow-Origin' : '*',
        'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT',
        'Content-Type': 'application/json; charset=UTF-8',
        'Accept': 'application/json',
        'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
    });

在我设置的config.xml文件中:

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

但是运行到ios模拟器时出现同样的错误,我应该怎么解决这个问题?

【问题讨论】:

    标签: ionic-framework ionic2


    【解决方案1】:

    我在 Windows 10 上发现了我的问题并想分享。我希望它提供一些见解。 Windows 8.1/10 上的 UWP 拒绝回送。必须设置为豁免。

    Can't see localhost from UWP app

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2017-11-08
      • 2018-08-16
      • 2017-01-24
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 2018-10-13
      相关资源
      最近更新 更多