Azure golang函数未在正文中接收请求有效负载
时间:2024-04-09
浏览:160
作者:佚名
今天golang学习网给大家带来了《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"
}
在日志中,我看到:
时间=“2020-07-31t01:14:11z”级别=信息消息=“正文:”
函数.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
关于如何调试这个问题有什么建议吗?
解决方案
这是基于 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
今天关于《Azure golang函数未在正文中接收请求有效负载》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
站内热门
最新文章
热门专题
