尝试对 POST API 执行测试时发生以下错误
events.js:71 抛出参数 [1]; // 未处理的“错误事件”错误:在 Object.afterConnect [as oncomplete] (net.js:760:19) 的 errnoException (net.js:769:11) 处连接 ECONNREFUSED
代码如下:
var http = require('http');
assert = require('assert')
var opts = {
host:'localhost',
port:8000,
path:'/send',
method:'POST',
headers:{'content-type':'application/x-www-form-urlencoded'}
}
var req = http.request(opts,function(res) {
res.setEncoding('utf8')
var data = ""
res.on('data', function(d) {
data += d
})
res.on('end',function() {
assert.strictEqual(data, '{"status":"ok","message":"Tweet recieved"}')
})
})
req.write('tweet=test')
req.end()