我们如何使用 node.js 的 HTTP/Request 模块连接到 Dash DB 并执行 R-script 代码。我可以使用 Node-RED 来完成,但喜欢以编程方式完成。现在我收到此错误:
0530 [App/0] ERR Potentially unhandled rejection [2] Error: EACCES, mkdir '/home/nol'
0530 [App/0] OUT STATUS: 500
0530 [App/0] OUT HEADERS: {""content-type":"text/html; charset=UTF-8","set-cookie":Path=/; Secure; HttpOnly"],"connection":"Close", ""}
0530 [App/0] OUT BODY:
0530 [App/0] OUT An internal error has occurred. The application may still be initializing or the URL used is invalid. Check the URL and try again. For more information, view the server log files.
下面是我的代码:
var options = {
hostname: 'bluemix05.bluforcloud.com',
host:'50.97.93.115',
port: 8443,
path: ':/console/blushiftservices/BluShiftHttp.do',
method: 'POST',
username: 'xxxxxxxxx',
password: 'xxxxxxxxx',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization' : 'Basic ' + new Buffer(username + ':' + password).toString('base64')
}
};
var postData = querystring.stringify({
'msg' : 'cmd=RScriptRunScript&command=library\(ibmdbR\)\ncon <- idaConnect(\"BLUDB\",\"\",\"\")\nidaInit(con)\nSUB_NUM <- c\(0877777777\)\nPAST_YR_AVG <- c\(300\)\nTestUsageTable1<- data.frame \(SUB_NUM,PAST_YR_AVG,stringsAsFactors=FALSE\)\nsqlSave\(con, TestUsageTable1, rownames=FALSE,safer=FALSE,append=TRUE\)&profileName=BLUDB'
});
var req = http.request(options, function (res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
loggererror.info('STATUS: ' + res.statusCode);
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
loggererror.info('Status: ' + e.message);
});
req.write(postData);
req.end();