var http = require("https"); var url = require('url'); var postData = JSON.stringify( { "header": { "account_type": "1", "password": "XXX", "token": "XXX", "username": "XXX" }, "body": { "siteId": 11111, "method":"visit/toppage/a", "start_date":"20190227", "end_date": "20190227", "metrics": "pv_count,visitor_count", "gran":"day" } }); var options = { hostname: url.parse("https://api.baidu.com").hostname, path:'/json/tongji/v1/ReportService/getData', port:443, method:"POST", }; var req = http.request(options,function(res) { res.setEncoding("utf-8"); res.on("data",function(chunk){ console.log("data: "); console.log(chunk.toString()); }); console.log(res.statusCode); }); req.on("error",function(err){ console.log(err.message); }); req.write(postData); req.end();
百度需要的是json数据