var http=require('http');
var body = {
"data":{
"id" : id,
"zjCount" : zjCount,
"number" : number
}
};
var bodyString = JSON.stringify(body);
var headers = {
'Content-Type': 'application/json',
'Content-Length': bodyString.length
};
var options = {
host: '127.0.0.1',
port: 80,
path: '/admin778899.php/api/kaijiang',
method: 'POST',
headers: headers
};
var req=http.request(options,function(res){
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
log(data);
});
res.on('end', function(res) {
//这里接收的参数是字符串形式,需要格式化成json格式使用
//var resultObject = JSON.parse(responseString);
log(res);
});
req.on('error', function(e) {
// TODO: handle error.
log('-----error-------',e);
});
});
req.write(bodyString);
req.end();
接口那边是 PHP 写的,不知道怎么获取我想要的bodyString ?