Azure golang 函数未在正文中接收请求有效负载

我在 Go 中创建了一个 Azure 函数。该功能在具有 GET 和 POST 请求的本地机器上正常工作。发布后,通过 POST 发送的请求有效负载在请求对象中不可用。这是我的代码:


# Main function

mux := http.NewServeMux()

mux.HandleFunc("/hello", helloWorld)

logrus.Fatal(http.ListenAndServe(":"+httpInvokerPort, mux))


# helloWorld function

func helloWorld(w http.ResponseWriter, r *http.Request) {

    logrus.Info("hello: inside helloWorld")


    bodyBuffer, err := ioutil.ReadAll(r.Body)

    if err != nil {

        logrus.Info("error while reading:" + err.Error())

        w.Write([]byte("GO: error in reading request body"))

    } else {

        logrus.Info("body : " + string(bodyBuffer))


        w.Write([]byte("GO: return hello"))

    }

}


部署后,我使用以下 JSON 正文调用 POST api 请求:


    "a": "b"

}

在日志中,我看到:


time="2020-07-31T01:14:11Z" level=info msg="body :"


函数.json:


{

    "bindings": [

        {

            "authLevel": "anonymous",

            "type": "httpTrigger",

            "direction": "in",

            "name": "req",

            "methods": ["get", "post"]

        },

        {

            "type": "http",

            "direction": "out",

            "name": "res"

        }

    ]

}

我的代码托管在这里:https ://github.com/mpurusottamc/azurefunc-go


关于如何调试这个的任何建议?


Smart猫小萌
浏览 160回答 1
1回答

凤凰求蛊

这是基于 Windows 操作系统的功能应用程序的问题。当我将操作系统类型更新为 Linux 时,我开始接收请求负载。这是我的functionapp创建命令:az functionapp create --resource-group hellogogrplinux --os-type Linux --consumption-plan-location eastus --runtime node --runtime-version 10 --functions-version 3 --name hellogoapplinux --storage-account hellogostglinux这是我更新的日志:time="2020-08-06T03:21:38Z" level=info msg="body : {\n \"a\": \"b\"\n}"这是 Azure Functions 主机上的一个已知问题,现已解决。本周将作为运行时版本的一部分推出:3.0.14251此 github 问题有更多详细信息:https ://github.com/Azure/azure-functions-host/issues/6444
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go