node js 发送http请求
来源:互联网 发布:java反射机制教程 编辑:程序博客网 时间:2024/06/05 07:02
get 请求
var url="http://apicloud.mob.com/lottery/list?key=1ebe77faca8b0";var http=require("http");http.get(url,function (req) { var html=""; req.on("data",function (data) { html+=data; }); req.on("end",function () { console.log(html); }); req.on("error",function (error) { console.log(error); });})
// post 请求var http=require("http");var queryString=require("querystring");var data={ "menu":"红烧肉", "key":"cad35b62a5b43c5bc9a98e01ba69532b"};var postData=queryString.stringify(data);console.log(JSON.stringify(data));var option={ host:"apis.juhe.cn", //不能加 http,默认已经http: path:"/cook/query.php", method:"POST", headers:{ 'Content-Type': 'application/x-www-form-urlencoded' // 'Content-Length':Buffer.byteLength(postData) }};var req=http.request(option,function (res) { console.log('Status:',res.statusCode); // console.log('headers:',JSON.stringify(res.headers)); var html=""; res.on("data",function (data) { html=html+data; }); res.on("end",function () { console.log(html); })});req.on("error",function (error) { console.error(error);})req.write(postData);req.end();
//get
var http=require("http");var queryString=require("querystring");var data={ "menu":"红烧肉", "key":"cad35b62a5b43c5bc9a98e01ba69532b"};var content=queryString.stringify(data);var options={ host:"apis.juhe.cn", //不能加 http,默认已经http: path:"/cook/query.php?"+content, method:"GET",};var req=http.request(options,function (res) { var html=""; res.on("data",function (data) { html=html+data; }); res.on("end",function () { console.log(html); })});req.on("error",function (error) { log.error(error);});req.end();
阅读全文
0 0
- Node.js发送HTTP请求
- node js 发送http请求
- node.js发送http(get,post)请求
- Node.Js http模块(一)-发送http请求实例
- Node.js中http 接收get请求、接收post请求、发送get请求、发送post请求
- Node.js输出HTTP请求
- Node.js http服务器搭建和发送http的get,post请求
- 封装js发送http请求
- 第一个 node js http 发送post请求(测试无误)
- 从零开始学习Node.js例子七 发送HTTP客户端请求并显示响应结果
- node.js中使用http模块发送请求时的一个小错误
- node.js+android http请求响应
- node.js+android http请求响应
- node.js+Android http请求响应
- node.js+Android http请求响应
- node.js解析http请求数据
- node.js实现本地http请求
- node 发送post请求
- bind函数详解
- 回溯法解决八皇后问题
- Java中在特定区间产生随机数和随机字符
- A new Graph Game HDU
- Windows中Oracle使用Doc命令完成数据的导出(EXP)/导入(IMP)
- node js 发送http请求
- 自己学校出cha的dian联zheng考jie(11.7)
- Dcloud HTML5 监听蓝牙设备 调用 原生安卓实现
- C语言井字棋
- 图片等比压缩
- laravel框架实现一个简单网站的思路
- 数据结构与算法分析c++:算法分析
- 高并发下redis的瓶颈分析
- 记录