【问题标题】:Redirection error 301 and 302 with requesting web api using Alamofire使用 Alamofire 请求 Web api 时出现重定向错误 301 和 302
【发布时间】:2018-07-10 18:43:12
【问题描述】:

最近我购买了SSL,并使用.htaccess将我服务器上的所有请求从http重定向到https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

但是,我的 iOSAndroid 应用程序已经从 http 请求来自 Alamofire 网络库的服务,因此它显示以下错误

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
    <title>302 Found</title>
</head>
<body>
    <h1>Found</h1>
    <p>The document has moved 
        <a href="https://api.example.com/webservices/v1/services.php">here</a>.
    </p>
</body>
</html>

我知道 301 和 302 是重定向错误,但网络服务显示来自浏览器的正确数据。来自应用程序的请求不起作用。

即使发生重定向也能接收正确 JSON 数据的任何解决方案。

请提出建议。任何帮助表示赞赏。

PS:还有其他原因我无法在应用程序中更改请求。

【问题讨论】:

    标签: php ios .htaccess redirect alamofire


    【解决方案1】:

    试试这个:

    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
    

    这会将301 重定向添加到.htaccess

    所以,完整的代码是:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2014-12-04
      • 2019-09-09
      • 2019-01-19
      • 1970-01-01
      相关资源
      最近更新 更多