12345678910111213141516171819202122232425262728293031323334353637383940 |
- var http = require('http');
- var querystring = require('querystring');
- function httpPost(path,data){
- var post_data = JSON.stringify(data);
-
- var options = {
- host: 'xcx.chuangzhikeji.com',
- port: 80,
- path: path,
- method: 'POST',
- headers:{
- 'Content-Type':'application/json'
- }
- };
-
-
- var req = http.request(options, function (res) {
- if(res.statusCode === 200){
- console.log('发送后台数据成功')
- }else{
- console.log('STATUS: ' + res.statusCode);
- console.log('HEADERS: ' + JSON.stringify(res.headers));
- res.setEncoding('utf8');
- res.on('data', function (chunk) {
- console.log('BODY: ' + chunk);
- });
- }
- });
-
- // write data to request body
- req.write(post_data);
- req.end();
- }
- exports.httpPost = httpPost;
|