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

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

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

Go
Smart猫小萌 2022-06-21 10:57:58
我在 Go 中创建了一个 Azure 函数。该功能在具有 GET 和 POST 请求的本地机器上正常工作。发布后,通过 POST 发送的请求有效负载在请求对象中不可用。这是我的代码:# Main functionmux := http.NewServeMux()mux.HandleFunc("/hello", helloWorld)logrus.Fatal(http.ListenAndServe(":"+httpInvokerPort, mux))# helloWorld functionfunc 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关于如何调试这个的任何建议?
查看完整描述

1 回答

?
凤凰求蛊

TA贡献1825条经验 获得超4个赞

这是基于 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


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

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号