【发布时间】:2018-05-09 19:45:09
【问题描述】:
我目前正在构建一个离子应用程序,并在我的 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'; 模块进行发布请求。
【问题讨论】:
-
你弄明白了吗?
标签: ios iphone http ionic-framework cross-domain