http://nodejs.cn/api/http.html#http_http_request_options_callback
http://yijiebuyi.com/blog/8221eb14c8482e7efd1868946e99ea7c.html
1、源生 http.request 模块的做法
http.request({ method: 'POST', url: 'http://192.168.0.102', headers: { // 'Content-Type': 'application/json', // 'X-Requested-With': 'XMLHttpRequest', }, // 请求和回发的数据自动转变成了 json 对象 // 不需要在header中设置'Content-Type': 'application/json',也不需要手动JSON.stringify()转义Body postdata json: true, body: { 'Phone': mobile, 'Code': code, 'Pwd': pwd, 'Share': share }, }, function (err, response, body) { console.log(body); })
2、request模块(推荐)
request({ method: 'POST', url: 'http://192.168.0.102', headers: { // 'Content-Type': 'application/json', // 'X-Requested-With': 'XMLHttpRequest', }, // 请求和回发的数据自动转变成了 json 对象 // 不需要在header中设置'Content-Type': 'application/json',也不需要手动JSON.stringify()转义Body postdata json: true, body: { 'Phone': mobile, 'Code': code, 'Pwd': pwd, 'Share': share }, }, function (err, response, body) { console.log(body); })