尝试使用请求模块向我的服务器的limesurvey remotecontrol API发出POST请求时,我收到了ECONNREFUSED错误(如下所示)。有什么我做错了吗?代码低于错误。
编辑修复了http://之间的空格,现在出现了新错误。
新错误:
{"id":null,"result":null,"error":"unable to decode malformed json"}
错误:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
代码:
var options = {
"url": "http://localhost/limesurvey/index.php/admin/remotecontrol",
"headers": {
"Host": "dev-rheumpro.cis.uab.edu",
"Content-Type": "application/json",
"Connection": "Keep-Alive",
"Content-Length": "65",
"Port": "80",
"User-Agent": "request"
},
"body": '{ "method": "get_session_key", "params": { "username": "admin", "password":"password" },"id": 1}'
}
request.post("http: //localhost/limesurvey/index.php/admin/remotecontrol", options, function callback(error, response, body) {
if(!error && response.statusCode == 200){
console.log("testing");
}
else {
console.log(error);
}
});
答案 0 :(得分:0)
将“ id”(1)更改为(“您的调查ID”)。