亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不允許獲取錯誤方法和內容類型:文本/純文本

不允許獲取錯誤方法和內容類型:文本/純文本

Go
眼眸繁星 2022-09-26 15:22:26
我的所有路線都完美運行,除了.每當我使用該方法添加數據時,它都會給我消息。當我檢查方法標頭內容類型時,它是應用程序/ json,但是當我檢查方法標頭內容類型時,它是文本/純;charset = utf-8。所以我認為內容類型一定存在問題。我不明白如何解決這個問題。我附上了屏幕截圖以供參考。截圖: 路線:CreateGoalPostmethod not allowedGetPostfunc Setup(app *fiber.App) {    app.Get("/goals", controllers.GetGoals)    app.Get("/goals/:id", controllers.GetGoal)    app.Post("/goals/add", controllers.CreateGoal)    app.Put("/goals/:id", controllers.UpdateGoal)    app.Delete("/goals/:id", controllers.DeleteGoal)}控制器:import (    "strconv"    "github.com/gofiber/fiber/v2")type Goal struct {  Id        int    `json:"id"`  Title     string `json:"title"`  Status        bool   `json:"status"`}var goals = []*Goal{    {        Id:        1,        Title:     "Read about Promises",        Status:         true,    },    {        Id:        2,        Title:     "Read about Closures",        Status:         false,    },}func GetGoals(c *fiber.Ctx) error {    return c.Status(fiber.StatusOK).JSON(    // "success":  true,    // "data": fiber.Map{            // "goals": goals,        // },        goals,  )}func CreateGoal(c *fiber.Ctx) error {    type Request struct {        Title string `json:"title"`    }    var body Request    err := c.BodyParser(&body)    if err != nil {        return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{            "success": false,            "message": "Cannot parse JSON",            "error":   err,        })    }    goal := &Goal{        Id:        len(goals) + 1,        Title:     body.Title,        Status: false,    }    goals = append(goals, goal)    return c.Status(fiber.StatusCreated).JSON(fiber.Map{        "success": true,        "data": fiber.Map{            "goal": goal,        },    })}
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

您的終端節點位于方法的應用程序中。但是在《郵遞員》中,你叫/goals/addPOST/goals

在應用程序中期待請求。這就是為什么有方法不允許。/goalsGET


查看完整回答
反對 回復 2022-09-26
  • 1 回答
  • 0 關注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號