I need a little help. I am creating an Azure function to generate a token using NodeJS. Below is the function I have created.
const { response } = require('request');
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://abc.onbmc.com/api/jwt/login',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive'
},
form: {
'username': 'abc@xyz.com',
'password': 'password123'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
context.res = {
//status: 200, /* Defaults to 200 */
body: response.body
};
}
)
}
I am able to display the required output through console.log but am not able to display it in the response body. Response body just shows the HTTP requested is completed successfully.
HTTP/1.1 200 OK
Connection: close
Date: Tue, 14 Sep 2021 16:32:39 GMT
Content-Type: text/plain; charset=utf-8
Server: Kestrel
Content-Length: 0
Any help is appreciated.