我有点击POST
URL 并接收数据的代码。下面是代码:
var postdata="{u:1}";
var options = {
host: 10.0.0.1,
port: 80,
path: /ddd,
method: post
};
var reqClient = http.request(options, function(res)
{
var data = '';
res.setEncoding('utf8');
});
//setting the request contenet type to application/json
reqClient.setHeader('Content-Type','application/json');
//Posts the data to the Server
reqClient.write(postData);
reqClient.end();
reqClient.on('response', function (res)
{
var data = '';
res.on('data', function (chunk)
{
data+=chunk;
});
res.on('end',function(){
//Perform some functions
});
}).on('error', function(){
//error handler
}); ;
我必须处理一个错误,比如当服务器无法访问客户端 URL 时。我可以按照上述方法吗?我被困在这里。