node 请求
来源:互联网 发布:audition for mac 编辑:程序博客网 时间:2024/06/01 08:40
入口文件调用
var _http = require('./http.js');require('./login.js')(app, _http);
http.js文件
var http = require('http');var https = require('https');var util = require('util');process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // https请求/* * GET * url 访问路径 * '/a/company/list?sid=sid' * fun 回调方法 * function(cont),cont返回的数据 */exports.GET = function(url, fun) { var cont = '', url = 'http://tpos.yingzixia.com' + url; http.get(url, function(res) { res.setEncoding('utf-8'); res.on('data', function(chunk) { cont += chunk; }); res.on('end', function() { fun(cont); }); }).on('error', function(err) { console.log("Got error: " + err.message); });};/* * POST * postData 传递参数 * { * 'account': name, * 'passwd': md5(passwd) * } * url 访问路径 * '/a/app/login' * fun 回调方法 * function(cont),cont返回的数据 */exports.POST = function(postData, url, fun) { var querystring = require('querystring'); postData = querystring.stringify(postData); var cont = '', options = { hostname: 'tpos.yingzixia.com', path: url, port: 80, method: 'POST', headers: { 'Content-Length': postData.length, 'Content-Type': 'application/x-www-form-urlencoded' } }, req = http.request(options, function(res) { res.on('data', function(chunk) { cont += chunk; }); res.on('end', function() { try { cont = JSON.parse(cont); fun(cont); } catch (e) { fun(cont); } }); }); req.on('error', function(e) { console.log('Error: ' + e.messsage); }); req.write(postData); req.end();};/* * HTTPS POST请求 */exports.POST2 = function(postData, url, fun) { var querystring = require('querystring'); postData = querystring.stringify(postData); var cont = '', options = { hostname: 'tpos.yingzixia.com', path: url, port: 443, method: 'POST', headers: { 'Content-Length': postData.length, 'Content-Type': 'application/x-www-form-urlencoded' } }, req = https.request(options, function(res) { res.on('data', function(chunk) { cont += chunk; }); res.on('end', function() { try { cont = JSON.parse(cont); fun(cont); } catch (e) { fun(cont); } }); }); req.on('error', function(e) { console.log('Error: ' + e.messsage); }); req.write(postData); req.end();};
0 0
- node 请求
- node处理get请求
- Node中的HTTP请求
- node 发送post请求
- node中https请求
- node-异步请求
- node.js 接收get请求
- node.js 接收post请求
- Node.js GET/POST请求
- node.js获取请求参数
- Node.js GET/POST请求
- node 阻止favicon.ico请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- Node.js GET/POST请求
- node+express----请求对象req
- Redis + Node.js: 请求缓存
- 关于java中byte
- 企业APP开发应该关注的那些问题
- ToggleButton和Switch改变布局
- 保存的文章
- sys下文件创建 实例
- node 请求
- 使用Mahout搭建推荐系统之入门篇4-Mahout实战
- Java之多线程内存可见性_1
- python34+pyserial2.7+PyQt5开发环境配置方法
- QT配置问题
- 单选,多选及其OnCheckedChange监听器
- 一款炫酷Loading动画--加载失败
- Rich Go language support for Visual Studio Code
- 3g驱动移植