我正在使用Azure Function App来部署此示例代码:
FUNCTIONS_EXTENSION_VERSION =测试
WEBSITE_NODE_DEFAULT_VERSION = 6.5.0
index.js:
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
}
else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
context.done(); };
function.json:
{"disabled": false, "bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}]}
在本地开发中,一切正常。
部署后,请求POST的正文为“未定义”
调用该函数的简单请求: - content-type:application / json
{
"name":"John"
}
日志:
{ method: 'POST',
url: '/api/MyHttpTrigger',
originalUrl: '/api/MyHttpTrigger',
headers:
{ connection: 'close',
'transfer-encoding': 'chunked',
accept: 'application/json, text/plain, */*',
authorization: 'Bearer------',
expect: '100-continue',
host: 'dev-we-function-test-api.azurewebsites.net',
'max-forwards': '10',
'user-agent': 'axios/0.16.2',
'x-client-ip': '52.143.137.149',
'x-client-port': '16079',
'request-context': 'appId=cid-v1:5443f5a3-02cd-43d3-90d6-1942e07580a1,roleName=Web',
'request-id': '|rtHs1.ca2e9979_1310.',
'x-ms-request-id': 'rtHs1',
'x-ms-request-root-id': '|rtHs1.ca2e9979_1310.',
'x-waws-unencoded-url': '/api/MyHttpTrigger?code=NhpwrmvOjo809ryOvkzbbBa9B1/Hqj18FoVw9faqq8eKSaoDk4oyeg==',
'client-ip': '52.143.137.149:16079',
'is-service-tunneled': '0',
'x-arr-log-id': 'c2b5dbe9-4193-4b81-821a-8ad2054a1203',
'disguised-host': 'dev-we-function-test-api.azurewebsites.net',
'x-site-deployment-id': 'dev-we-function-test-api',
'was-default-hostname': 'dev-we-function-test-api.azurewebsites.net',
'x-original-url': '/api/MyHttpTrigger?code=NhpwrmvOjo809ryOvkzbbBa9B1/Hqj18FoVw9faqq8eKSaoDk4oyeg==',
'x-forwarded-for': '52.143.137.149:16079',
'x-arr-ssl': '2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT TLS CA 4|CN=*.azurewebsites.net',
'x-forwarded-proto': 'https' },
query:
{ code: 'NhpwrmvOjo809ryOvkzbbBa9B1/Hqj18FoVw9faqq8eKSaoDk4oyeg==' },
params: {},
body: undefined }
帮助...
答案 0 :(得分:0)
重现我身边的错误。
做了一些测试来检测原因。
因此,对于Linux应用服务计划(预览)中的js函数,请求正文丢失或无法从我的角度解析。这似乎是linux版本的语言支持问题,因为整个部署是一个模板,并且没有关于不支持作为请求主体的json数据的提示。
<强>更新强>
此问题似乎已解决,请在运行时2.0.1.0(beta)for linux上进行测试。