Hey All,
I need some help using node.js to make a http post to call my function on the spark core. I am definitely missing something fundamental.
var http = require('http');
var data = JSON.stringify({
"access_token": "123123213213123",
"args": "990"
});
var options = {
host: 'api.spark.io',
port: 443,
path: '/v1/devices/1231231232131231213/myFunc',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data)
}
};
var req = http.request(options, function(res) {
var result = '';
res.on('data', function(chunk) {
result += chunk;
});
res.on('end', function() {
console.log(result);
});
});
req.on('error', function(err) {
console.log(err);
});
req.write(data);
req.end();
I keep getting: { [Error: socket hang up] code: ‘ECONNRESET’ }
note: myFunc is registered/defined and takes an argument of string on my core.
Please help.
Thanks!