错误:套接字挂断代码:Node.js中的“ECONNRESET”

时间:2017-03-17 11:09:42

标签: javascript node.js sockets http

我试图在Node.js上使用HTTP请求发布文件,但是在发布了一些文件后,它会随机显示 [错误:套接字挂断]代码:'ECONNRESET'

我的文件发送代码是,

var http = require('http');
var request = require('request');
var fs= require('fs');
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

var serverUrl='http://localhost:3000'; 

function uploadFile(){
	var req = request.post(serverUrl+'/api/file/upload', function (err, resp, body) {
	if (err) {
	    console.log(err);
	  } else {
      console.log(body);
	  }
	});
	var form = req.form();
	form.append('file', fs.createReadStream('abcd.mp3'));
}

uploadFile();

server.listen(8000);

0 个答案:

没有答案