【发布时间】:2019-07-16 13:46:48
【问题描述】:
我目前正在从 aws lambda 切换到 azure 函数,并尝试将我的 lambda 函数 (js) 转换为 azure 函数 (js)。我需要在我的函数中做的一件事是将 HTTPS 发布请求发送到 URL 以获取一些数据。这在 aws lambda 中运行良好。但是,似乎 azure 函数要么不支持这一点,要么我做错了,因为它从不发送请求,只是结束了整个函数。
这是我的代码:
var https = require('https');
var http = require('http');
module.exports = async function (context, req) {
var http_options = {
hostname: 'somehostname',
port: 443,
path: 'somepath',
method: 'POST',
headers: {
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': '"https://someURL"'
}
};
var body = '';
context.log('before request');
var req = await https.request(http_options, function (res) {
res.setEncoding('utf8');
body = '';
context.log('inside request');
res.on('data', (chunk) => {
body = body + chunk;
});
context.log('in req 2');
res.on('end', () => {
var options = {
compact: false,
ignoreComment: false,
spaces: 1
};
var result = JSON.parse(body);
})
})
};
该函数总是打印“请求前”部分,然后就终止了。
我还尝试了一个简单的 http 调用,如this SO 问题中所述。然而,同样的结果,函数刚刚结束。
【问题讨论】:
标签: javascript node.js azure https azure-functions