菜鸟教程小白 发表于 2022-12-11 19:22:09

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 &#39;body&#39; and &#39;this.headers&#39; are correctly created

await this.http.post(&#39;/get-preferences&#39;, body, {headers: this.headers})
.toPromise().then(data =&gt; {

      //Logs everything as a correct result on web
      //The following line is what displays the above error through XCode through the iphone.

    }).catch(err =&gt; console.log(&#34;Error getPreferences occured: &#34;, (&lt;Error&gt;err).message));
}
</code></pre>

<p>我用 google 搜索了一下,向 <code>ionic.config.json</code> 添加代理应该可以解决 web 和 iphone 的问题,但不知何故手机版本无法正常工作。 </p>

<p>这是我的 <code>ionic.config.json</code> 的内容:</p>

<pre><code>{
&#34;name&#34;: &#34;ionic2-app-base&#34;,
&#34;app_id&#34;: &#34;&#34;,
&#34;type&#34;: &#34;ionic-angular&#34;,
&#34;integrations&#34;: {
    &#34;cordova&#34;: {}
},
&#34;proxies&#34;: [
    {
      &#34;path&#34;: &#34;/get-preferences&#34;,
      &#34;proxyUrl&#34;: &#34;http://serverIp/get-preferences&#34;
    },
    {
      &#34;path&#34;: &#34;/register-vote&#34;,
      &#34;proxyUrl&#34;: &#34;http:/serverIp/register-vote&#34;
    },
    {
      &#34;path&#34;: &#34;/create-user&#34;,
      &#34;proxyUrl&#34;: &#34;http://serverIp/create-user&#34;
    }
]
}
</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]
查看完整版本: ios - Http 失败响应 501 : Not implemented, altought 完全相同的方法适用于 web