HTTP故障响应501:未实施,Alt期在Web上完全相同的方法



我目前正在构建一个离子应用程序,并在iPhone 5s上部署开发版本。我部署了与网络浏览器上部署的完全相同的版本。Web浏览器上的版本正常工作,并且没有显示任何错误。

但是,当我在物理iPhone 5s上运行该应用时,我会收到以下错误:

Http failure response for http://localhost:8080/get-preferences: 501 Not Implemented

此错误是以下功能的结果:

//Logs that 'body' and 'this.headers' are correctly created
await this.http.post('/get-preferences', body, {headers: this.headers})
.toPromise().then(data => {
      //Logs everything as a correct result on web
      //The following line is what displays the above error through XCode through the iphone.
    }).catch(err => console.log("Error getPreferences occured: ", (<Error>err).message));
}

我谷歌搜索了一点,并且在ionic.config.json中添加代理应该为Web和iPhone解决了这个问题,但是以某种方式,电话版本无法正常工作。

这是我的ionic.config.json的内容:

{
  "name": "ionic2-app-base",
  "app_id": "",
  "type": "ionic-angular",
  "integrations": {
    "cordova": {}
  },
  "proxies": [
    {
      "path": "/get-preferences",
      "proxyUrl": "http://serverIp/get-preferences"
    },
    {
      "path": "/register-vote",
      "proxyUrl": "http:/serverIp/register-vote"
    },
    {
      "path": "/create-user",
      "proxyUrl": "http://serverIp/create-user"
    }
  ]
}

我还必须在iPhone上启用其他内容,这样 有效?

我正在使用import {HttpClient, HttpHeaders} from '@angular/common/http';模块作为发布请求。

我想您尝试使用地址htt htt://localhost:8080/...或http://127.0.0.1::8080/...

正常的是,它不起作用的本地主机是电话(甚至模拟)。

解决方案:使用PC/服务器的IP地址更改您的API URL本地主机:192.168.xx.xx

最新更新