You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Ocelot API网关时遇Hostname无法解析异常求助

问题排查与解决
  • 错误根源:
    异常System.UriFormatException: Invalid URI: The hostname could not be parsed.的直接原因是ocelot.json中第二个路由的DownstreamHostAndPorts配置错误:Host字段填写了带协议前缀的完整地址https://itapsuat.sslcapsec.com,而Ocelot要求Host仅需填写纯主机名(或IP),协议已通过DownstreamScheme指定为https,多余的https://会导致主机名解析失败。

  • 修正配置:
    将对应路由的Host值修改为纯主机名itapsuat.sslcapsec.com,修正后的配置片段如下:

    {
      "UpstreamPathTemplate": "/gateway/api/V1/SSL/GenrateToken",
      "UpstreamHttpMethod": [ "Post" ],
      "DownstreamPathTemplate": "/MasterAPI/api/v1/services/SSL/Token/GenrateToken",
      "DownstreamScheme": "https",
      "DownstreamHttpMethod": "POST",
      "DownstreamHostAndPorts": [
        {
          "Host": "itapsuat.sslcapsec.com", // 去掉https://前缀
          "Port": 443
        }
      ],
      "SwaggerKey": "Token",
      "RateLimitOptions": {
        "EnableRateLimiting": true,
        "Period": "10s",
        "PeriodTimespan": 10,
        "Limit": 3,
        "HttpStatusCode": 429
      }
    }
    
  • 验证步骤:

    1. 保存修改后的ocelot.json
    2. 重启Ocelot网关服务
    3. 通过网关的上游路径/gateway/api/V1/SSL/GenrateToken发起POST请求,确认是否能正常转发到下游API

内容的提问来源于stack exchange,提问作者Tanmay Nehete

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 19:47:21