ios - Http 失败响应 501 : Not implemented, altought 完全相同的方法适用于 web
<p><p>我目前正在构建一个 ionic 应用程序,并在我的 iphone 5s 上部署一个开发版本。我部署的版本与我在 Web 浏览器上部署的版本完全相同。网络浏览器上的版本运行良好,没有显示任何错误。</p>
<p>但是,当我在物理 iphone 5s 上运行该应用程序时,我收到以下错误:</p>
<pre><code>Http failure response for http://localhost:8080/get-preferences: 501 Not Implemented
</code></pre>
<p>此错误是以下函数的结果:</p>
<pre><code>//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));
}
</code></pre>
<p>我用 google 搜索了一下,向 <code>ionic.config.json</code> 添加代理应该可以解决 web 和 iphone 的问题,但不知何故手机版本无法正常工作。 </p>
<p>这是我的 <code>ionic.config.json</code> 的内容:</p>
<pre><code>{
"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"
}
]
}
</code></pre>
<p>还有什么我必须在 iphone 上启用的,比如这个
有效吗?</p>
<p>我正在使用 <code>import {HttpClient, HttpHeaders} from '@angular/common/http';</code> 模块进行发布请求。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您尝试使用地址 htt://localhost: 8080/... 或 <a href="http://127.0.0.1:8080/" rel="noreferrer noopener nofollow">http://127.0.0.1:8080/</a> 从模拟器 (ios/android) 访问 API ...</p>
<p>不工作 localhost 是手机是正常的(即使是模拟的)。</p>
<p>解决方案:将您的 api url localhost 更改为您的 pc/server 的 ip 地址,例如:192.168.xx.xx</p></p>
<p style="font-size: 20px;">关于ios - Http 失败响应 501 : Not implemented, altought 完全相同的方法适用于 web,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/47496216/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/47496216/
</a>
</p>
页:
[1]