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

Ocelot网关Get请求正常但Post请求返回400错误求助

Ocelot网关Post请求返回400 Bad Request问题

我用Ocelot做API网关时碰到个问题:Get请求能正常通过网关转发并拿到响应,但Post请求一直返回400 Bad Request。不过相同的Post请求直接在Postman里调用目标接口,却能成功返回200状态码。我确认Swagger和Postman调用的是同一个网关URL,所以初步排除了Ocelot配置文件的问题。

以下是我的Ocelot.json配置内容:

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44340
        }
      ],
      "UpstreamPathTemplate": "/gateway/v1/starter/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
      "SwaggerKey": "starter"
    },
    {
      "DownstreamPathTemplate": "/api/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 21021
        }
      ],
      "UpstreamPathTemplate": "/gateway/v1/abpstarter/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
      "SwaggerKey": "abpstarter"
    }
  ],
  "SwaggerEndPoints": [
    {
      "Key": "starter",
      "Config": [
        {
          "Name": "starter API",
          "Version": "v1",  
          "Url": "https://localhost:44340/swagger/v1/swagger.json"
        }
      ]
    },
    {
      "Key": "abpstarter",
      "Config": [
        {
          "Name": "abpstarter API",
          "Version": "v1",
          "Url": "http://localhost:21021/swagger/v1/swagger.json"
        }
      ]
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:3000",
    "RequestIdKey": "OcRequestId"
  }
}

内容的提问来源于stack exchange,提问作者Waleed Khaled

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 22:16:01