【问题标题】:How define ocelot configuration for POST method controllers net core?如何为 POST 方法控制器 net core 定义 ocelot 配置?
【发布时间】:2021-03-28 17:59:35
【问题描述】:

实际上,在我的 Api 服务中,我有一个方法控制器,例如:

[Produces("application/json")]
[ApiController]
[Route("api/v1/[controller]")]
public class LoginController: Controller
{
   public LoginController(IConfiguration config)
   {
     ...
   }

  [Route("authentication"),HttpPost]
  public async Task<IActionResult> Authentication(LogRequest request)
  {
    ...
  }
}

我的配置:

 "ReRoutes": [
 {
   "DownstreamPathTemplate": "/api/{version}/{everything}",
   "DownstreamScheme": "http",
   "DownstreamHostAndPorts": [
    {
     "Host": "tresfilos.users.service",
     "Port": 7002
    }
   ],
   "UpstreamPathTemplate": "/api/{version}/user/{everything}",
   "UpstreamHttpMethod": [ "POST", "PUT", "GET" ]
  },
 ],
  "GlobalConfiguration": {
  "BaseUrl":  "https://localhost:7001"
 }

我在邮递员中消费,例如: http://localhost:7000/api/v1/user/Login/authentication

而且我不知道我对豹猫配置文件的定义是否适合 POST 方法。

【问题讨论】:

    标签: asp.net-core post routes ocelot


    【解决方案1】:

    我现在定义如下:

    "Routes": [
      {
       "DownstreamPathTemplate": "/api/{version}/{everything}",
       "DownstreamScheme": "http",
       "DownstreamHostAndPorts": [
       {
         "Host": "tresfilos.users.service",
         "Port": 7002
       }
     ],
      "UpstreamPathTemplate": "/api/{version}/User/{everything}"
     },
    ],
     "GlobalConfiguration": {
     "BaseUrl":  "https://localhost:7001"
    }
    

    将 ReRoutes 更改为 Routes,因为我使用 ocelot 16.0.1 在邮递员中,我像 json 一样发送 Body 中的数据,而不是像参数一样。

    【讨论】:

      猜你喜欢
      • 2021-12-06
      • 1970-01-01
      • 2019-12-31
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 2019-01-13
      相关资源
      最近更新 更多