美文网首页
创建一个简单的client

创建一个简单的client

作者: zz张哲 | 来源:发表于2016-10-06 21:37 被阅读0次
var http = require('http');

var opt = {
    host: 'www.baidu.com',
    port: '80',
    method: 'GET',
    path: '/',
    hearders: {
        'Content-Type': 'application/json'
    }
};

var body = '';
var req = http.request(opt, function (res) {
    console.log('Got response: ' + res.statusCode);
    res.on('data', function (data) {
        body += data;
    });
    res.on('end', function () {
        console.log(res.headers);
        console.log(body);
    });
});

req.on('error', function (err) {
    console.log('Got error: ' + err.message);
});

req.write('');
req.end();

相关文章

网友评论

      本文标题:创建一个简单的client

      本文链接:https://www.haomeiwen.com/subject/wstyyttx.html