/**
 * Created by godsong on 16/7/22.
 */
const Https = require('https');
const Path = require('path');
const URL = require('url');
const protocols = {
    'http:':require('http'),
    'https:':require('https')
}
function getRemote(url) {
    return new Promise(function (resolve, reject) {
        let urlObj = URL.parse(url);
        protocols[urlObj.protocol].get({
            hostname: urlObj.hostname,
            port: urlObj.port,
            path: urlObj.path,
            method: 'GET',
            headers: {
                'User-Agent': 'Weex/1.0.0'
            }
        }, function (res) {
            var chunks = [];
            res.on('data', function (chunk) {
                chunks.push(chunk);
            });

            res.on('end', function () {
                resolve(Buffer.concat(chunks).toString());
                chunks = null;
            });
        }).on('error', function (e) {
            reject('');
        });
    });

}
getRemote('https://pages.tmall.com/wow/act/16280/meizhuang?wh_weex=true').then(function(data){
    console.log(data.substr(0,100));
}).catch(function(e){
    console.log(e)
});