以下 curl 命令完美地调用、传递参数和执行我的“jobified”火花程序
curl 'http://someserver:8090/jobs?appName=secondtest&classPath=Works.epJob&context=hiveContext' -d "inputparms=/somepath1 /somepath2"
这是火花程序
override def runJob(hive: HiveContext, config: Config):Any = {
var inputParms = config.getString("inputparms").split(" "); //comes from node
var path1 = inputParms.apply(0)
var path2 = inputParms.apply(1)
我需要在 node.js 中做一个 http 帖子,而不是 curl 命令。这是我所拥有的
var postData = JSON.stringify({
"inputparms": paths
})
var options = {
hostname: 'someserver',
port: 8090,
path: '/jobs?appName=secondtest&classPath=Works.epJob context=hiveContext',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData , 'utf8')
}
};
http.request(options, function(response) {...
但是,上面的脚本不起作用。我错过了什么吗?谢谢!
编辑1:
var myreq = http.request(options, function(response) { ...})
myreq.write(postData);
myreq.end();
我得到一个解析错误
Error: Parse Error
at Error (native)
at Socket.socketOnData (_http_client.js:361:20)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:177:18)
at Socket.Readable.push (_stream_readable.js:135:10)
at TCP.onread (net.js:542:20) bytesParsed: 2, code: 'HPE_INVALID_CONSTANT' }