Enn*_*nio 5 azure node.js azure-functions
我正在尝试使用 nodeJS 创建 Azure 函数,但是当我调用 https API 时,我收到一条错误消息。
是否可以从 azure 函数进行 HTTPS 调用?
这是我的代码
const https = require('https');
const querystring = require('querystring');
module.exports = async function (context, req) {
if (req.query.accessCode || (req.body && req.body.accessCode)) {
var options = {
host: 'api.mysite.com',
port: 443,
path: '/oauth/access_token',
method: 'POST'
};
var postData = querystring.stringify({
client_id : '1234',
client_secret: 'xyz',
code: req.query.accessCode
});
var req = https.request(options, function(res) {
context.log('STATUS: ' + res.statusCode);
context.log('HEADERS: ' + JSON.stringify(res.headers));
res.on('data', function (chunk) {
context.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
context.log('problem with request: ' + e.message);
});
req.write(postData);
req.end();
context.res = {
status: 200,
body: "Hello " + (req.query.accessCode)
};
} else {
context.res = {
status: 400,
body: "Please pass a name on the query string or in the request body"
};
}
context.done();
};
Run Code Online (Sandbox Code Playgroud)
我收到错误,但在控制台上没有看到任何错误,而且如果我注释所有 https 调用,它也可以正常工作,并且我可以在屏幕上看到 Hello 消息。
| 归档时间: |
|
| 查看次数: |
4624 次 |
| 最近记录: |