Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js错误,尝试发布到Limesurvey RC API时出现错误_Javascript_Json_Node.js_Http Post_Json Rpc - Fatal编程技术网

Javascript Node.js错误,尝试发布到Limesurvey RC API时出现错误

Javascript Node.js错误,尝试发布到Limesurvey RC API时出现错误,javascript,json,node.js,http-post,json-rpc,Javascript,Json,Node.js,Http Post,Json Rpc,当我尝试使用请求模块向服务器的limesurvey remotecontrol API发出POST请求时,出现如下所示的错误。我做错什么了吗?下面是代码错误 编辑:修复了http://now获取新错误之间的空格 新错误: {"id":null,"result":null,"error":"unable to decode malformed json"} 错误: { [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: '

当我尝试使用请求模块向服务器的limesurvey remotecontrol API发出POST请求时,出现如下所示的错误。我做错什么了吗?下面是代码错误

编辑:修复了http://now获取新错误之间的空格

新错误:

{"id":null,"result":null,"error":"unable to decode malformed json"}
错误:

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }
代码:


将'id',1更改为您的调查id。

也许这只是问题中的一个输入错误,但以防万一,您的代码中也有:请求中的'http:'和'/'之间有一个空格。postWow,我甚至没听清楚,谢谢。我修复了它,现在它给了我:“{id:null,result:null,error:unable-decoded-moreformed json}”“@BalafiJSON-RPC信封中的jsonrpc属性在哪里?服务器是否期望JSON-RPC信封的“命名”或“位置”参数,或者可能在JSON-RPC信封的params属性中?根据Limesurvey的API页面,它与jsonrpc 1类似,他们给出了一个没有提及jsonrpc的示例标题,尽管该网站声称它使用什么。我使用了Chrome中的Postman扩展来发布到我的服务器,它工作得很好。我是个新手,我不确定我的代码中是否遗漏了什么@大卫天空网
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);
}

});