美文网首页
nodejs获取请求数据

nodejs获取请求数据

作者: LaLaLaLaAAA | 来源:发表于2016-08-09 18:00 被阅读0次

    varhttp=require("http");
    varurlPath='http://127.0.0.1:8124/biz?'+
    'name=freddon&domain='+encodeURIComponent("http://www.sagosoft.com/");
    http.get(urlPath,function(response){
    response.setEncoding('utf-8');
    console.log("状态码%d\nheaders:\n%s\n当前的请求方式为【GET】请求",response.statusCode,
    JSON.stringify(response.headers));
    varreceiveData="";
    response.on('data',function(chunk){
    receiveData+=chunk;
    }).on('end',function(){//打印
    console.log("\n获得的数据为:"+receiveData);});
    }).on('error',function(e){
    console.log(e.message);});

    相关文章

      网友评论

          本文标题:nodejs获取请求数据

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