hello want use xively curl function. use nodejs retrieve values of arduino raspberry. know if know how use curl nodejs because after several attempts have failed. thank
if referring php curl, need know node.js has no "curl" (which stands "client url"). has http
module request
, get
methods in order make http requests. have same purpose phps curl.
you still can execute shell script using child_process.exec
, doing risk application run through exec might platform dependent, in case might work on windows , not on linux or similar issue. xively should use http.request - , job you. , easier, getting output curl
via child_process.exec
harder through http.request
.
so based on documentation in here: https://xively.com/dev/tutorials/curl/
have made http.request alternative in order query feed:
var data = json.stringify({ title: 'my feed', version: '1.0.0' }); var req = http.request({ host: 'api.xively.com', path: '/v2/feeds', method: 'post', headers: { 'x-apikey': 'your_api_key_here', 'content-type': 'application/json', 'content-length': data.length } }, function(res) { res.setencoding('utf8'); console.log('status code: ' + res.statuscode); console.log('headers:'); console.log(res.headers); var buffer = ''; res.on('data', function(chunk) { buffer += chunk; }); res.on('end', function() { console.log('complete'); console.log(buffer); }); }); res.write(data); res.end();
i've wrote code in browser, , not sure correct, please try out , let me know if there wrong, correct code above.
can see supports functionalities curl offers, , more flexible , nicer usage point of view.
feel free use them in order make http calls.
Comments
Post a Comment