【发布时间】:2017-08-19 19:50:33
【问题描述】:
好的,所以我已经为此苦苦挣扎了一段时间。我有一个应该可以工作的 curl 命令。由于我不熟悉 curl 我将其“翻译”为节点。但它不起作用。这是卷曲线。
curl -X POST --header 'Content-Type: application/json' --header 'token: XXXXXX' -d '[ \
{ \
"id": "eh", \
\
"kind": "goods", \
"data": {} \
} \
]' 'http://localhost:5000/api/article'
当我把它翻译成节点时,它看起来像这样:
var request = require('request');
var dataString = '[ \
{ \
"id": "eh", \
\
"kind": "goods", \
"data": {} \
} \
]';
var options = {
url: 'http://localhost:5000/api/article',
method: 'POST',
body: dataString
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
我得到的错误信息是
throw new TypeError('第一个参数必须是字符串或缓冲区');
谁能告诉我怎么了?谢谢
【问题讨论】:
-
你的代码的输出是什么?你预计会发生什么?
-
throw new TypeError('First argument must be a string or Buffer');
-
该错误出现在哪一行!?¿
-
_http_outgoing.js:456 throw new TypeError('第一个参数必须是字符串或缓冲区'); ^
-
认为我解决了,现在看看我的答案