接口调用失败,错误信息:<html> <head><title>301 Moved Permanently</title></head> <body> <cen...

2026年06月22日 13:59 14.91 秒 success

错误信息

接口调用失败,错误信息:<html> <head><title>301 Moved Permanently</title></head> <body> <center><h1>301 Moved Permanently</h1></center> <hr><center>openresty</center> </body> </html>

AI 解决方案

1. 🌐 错误翻译

原文:301 Moved Permanently
译文:301 永久重定向


2. 🎯 原因分析

这是 HTTP 301 状态码,表示请求的资源已永久移动到新的 URL 地址。

根本原因:

  • 📍 你请求的 API 地址已永久变更,服务器返回了重定向响应

  • 📍 可能使用了 http:// 而应使用 https://

  • 📍 API 路径可能缺少结尾的 / 或路径已更新

  • 📍 服务器(openresty)配置了强制跳转
  • 具体位置: 接口请求的 URL 地址


    3. 💡 解决方案

    方案一:跟随重定向,使用新的 URL

    # 先测试确认重定向目标
    curl -I http://your-api-domain.com/xxx
    # 查看 Location 头获取新地址
    

    方案二:代码中启用自动跟随重定向

    # Python requests 示例
    response = requests.get(url, allow_redirects=True)
    

    // Node.js axios 示例
    const response = await axios.get(url, {
      maxRedirects: 5,
      headers: { 'Accept': 'application/json' }
    });
    

    方案三:直接使用 HTTPS 协议

    - http://api.example.com/endpoint
    + https://api.example.com/endpoint
    

    方案四:检查 URL 格式

    - https://api.example.com/endpoint
    + https://api.example.com/endpoint/
    


    4. 🛡️ 预防措施

    建议说明
    统一使用 HTTPS大多数现代 API 都强制使用 HTTPS
    检查 API 文档调用前确认最新的接口地址
    启用重定向处理在 HTTP 客户端中配置自动跟随重定向
    💡 快速排查: 使用 curl -v <你的URL> 查看完整的请求响应过程,确认重定向的目标地址。