【问题标题】:error with nodejs PUT requestnodejs PUT请求错误
【发布时间】:2017-06-08 15:19:15
【问题描述】:

我在尝试使用 nodejs 执行以下 PUT 请求时遇到错误。

var request = require('request');
request('http://1xx.xxx.xxx.xxx:8080/maintable/http%3A%2F%2Ftesturl.com
  %2F', 
method: 'PUT', 
json:{"Row":[{"key":"aHR0cHM6Ly9tYWt6ZW9uLndvcmRwcmVzcy5jb20v", "Cell": 
 [{"column":"YmxvZ3NfZGF0YTp1cmw=", "$":    
 "aHR0cHM6Ly9tYWt6ZW9uLndvcmRwcmVzcy5jb20v"},
 {"column":"YmxvZ3NfZGF0YTppbnNlcnREYXRl", "$": "MTQ5Njg3ODk1OA=="},    
 {"column":"YmxvZ3NfZGF0YTpzdGF0dXM=", "$": "QWN0aXZl"}], 
}]}, 
function (error, response, body) {
    console.log('error:', error);
    console.log('statusCode:', response && response.statusCode);
    console.log('body:', body);
}
);

错误:

 method: 'PUT',
    ^^^^^^
 SyntaxError: missing ) after argument list
 at createScript (vm.js:56:10)
 at Object.runInThisContext (vm.js:97:10)
 at Module._compile (module.js:542:28)
 at Object.Module._extensions..js (module.js:579:10)
 at Module.load (module.js:487:32)
 at tryModuleLoad (module.js:446:12)
 at Function.Module._load (module.js:438:3)
  at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)

有人注意到错误在哪里吗?

【问题讨论】:

  • 已经有了答案,但请查看jsonformatter.curiousconcept.com 众多站点之一,以满足您未来手动输入的 json 验证需求;)
  • 感谢您的链接。

标签: node.js rest put


【解决方案1】:

请求函数的第一个参数遗漏了'{'

var request = require('request');
request({
    uri: 'http://1xx.xxx.xxx.xxx:8080/maintable/http%3A%2F%2Ftesturl.com', 
    method: 'PUT', 
    json:{
        "Row":[
            {
                "key":"aHR0cHM6Ly9tYWt6ZW9uLndvcmRwcmVzcy5jb20v", 
                "Cell": [
                    {
                        "column":"YmxvZ3NfZGF0YTp1cmw=", 
                        "$": "aHR0cHM6Ly9tYWt6ZW9uLndvcmRwcmVzcy5jb20v"
                    },
                    {
                        "column":"YmxvZ3NfZGF0YTppbnNlcnREYXRl", 
                        "$": "MTQ5Njg3ODk1OA=="
                    },    
                    {
                        "column":"YmxvZ3NfZGF0YTpzdGF0dXM=", 
                        "$": "QWN0aXZl"
                    }
                ], 
            }
        ]
    }
}, 
function (error, response, body) {
    console.log('error:', error);
    console.log('statusCode:', response && response.statusCode);
    console.log('body:', body);
});

【讨论】:

  • 谢谢我终于弄明白了,但感谢您的回复。
猜你喜欢
  • 2019-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 2018-06-14
  • 1970-01-01
  • 2020-06-22
  • 2017-11-18
相关资源
最近更新 更多