为了账号安全,请及时绑定邮箱和手机立即绑定

Krakend http:在封闭的身体上阅读无效

Krakend http:在封闭的身体上阅读无效

Go
摇曳的蔷薇 2022-11-15 17:10:59
我正在使用 Krakend 构建一个 API 网关来连接三个后端服务。网关总是从一个或两个后端服务返回,并且X-Krakend-Completed header总是设置为 false。http: invalid Read on closed Body日志中错误的原因可能是什么?预期行为GET localhost:8000回复{    "user-id": 1,    "payments-id": 1,    "loans-id": 1,}实际行为GET localhost:8000回复{    "payment-id": 1}Krakend日志[GIN] 2022/03/01 - 16:29:41 | 200 |     801.319µs |             ::1 | GET      "/"Error #01: Get "http://localhost:5000/users": http: invalid Read on closed BodyGet "http://localhost:6000/loans": http: invalid Read on closed Body[GIN] 2022/03/01 - 16:29:55 | 200 |     851.735µs |             ::1 | GET      "/"Error #01: Get "http://localhost:6000/loans": http: invalid Read on closed BodyGet "http://localhost:5000/users": http: invalid Read on closed Body服务 1type Payment struct {    Id int32 `json:"payment-id"`}var payments = []Payment{    {        Id: 0,    },    {        Id: 1,    }}func main() {    app := fiber.New()    app.Get("/payments", func(c *fiber.Ctx) error {        return c.JSON(payments[1])    })    app.Listen(":7000")}服务 2func main() {    app := fiber.New()    app.Get("/loans", func(c *fiber.Ctx) error {        return c.JSON(loans[1])    })    app.Listen(":6000")}服务 3func main() {    app := fiber.New()    app.Get("/users", func(c *fiber.Ctx) error {        return c.JSON(users[1])    })    app.Listen(":5000")}Krakend.json{    "version": 2,    "timeout": "3000ms",    "cache_ttl": "300s",    "output_encoding": "json",    "name": "users",    "port": 8000,    "read_timeout": "2s",    "write_timeout": "2s",    "idle_timeout": "2s",    "read_header_timeout": "2s",    "endpoints": [      {        "endpoint": "/",        "method": "GET",        "output_encoding": "json",        "backend": [          {            "url_pattern": "/users",            "encoding": "json",            "method": "GET",            "host": [              "http://localhost:5000"            ]          },        
查看完整描述

1 回答

?
青春有我

TA贡献1784条经验 获得超8个赞

我在 GET 请求中不知不觉地发送了一个正文,导致了Krakend http: invalid Read on closed Body错误

链接到Github 问题


查看完整回答
反对 回复 2022-11-15
  • 1 回答
  • 0 关注
  • 91 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信