node下使用request转发http请求
来源:互联网 发布:java web项目重新编译 编辑:程序博客网 时间:2024/05/16 08:55
在nodejs的开发中,有时需要后台去调用其他服务器的接口,这个时候,就需要发送HTTP请求了。有一个简单的工具可以用,Simplified HTTP request client,可以比较方便的模拟请求。
安装request模块
在项目的node_module文件夹下执行以下命令
npm install request --save
使用
get请求
var request = require('request');request('http://www.baidu.com', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) // Show the HTML for the baidu homepage. }})
post请求
var request = require("request");var express = require("express");var app = express();app.post("/index", (req, res) => { request({ url: "http://www.linyimin.club:10010/getService", method: "POST", json: true, headers: { "content-type": "application/json", }, body: JSON.stringify(req.body) }, function(error, response, body) { if (error) { console.log('------------------------------------'); console.log(error); res.send(error); res.end(); console.log('------------------------------------'); }else{ console.log('------------------------------------'); console.log(body); console.log('------------------------------------'); res.send(JSON.stringify(body)); res.end(); } }); })app.listen(3000);
阅读全文
0 0
- node下使用request转发http请求
- Springmvc 请求转发 No mapping found for HTTP request
- servlet request请求转发
- Request对象请求转发
- request请求转发
- http请求利器---node.js中的request模块
- nodejs使用request发送http请求
- 黑马day04 request&请求转发
- request请求转发相关知识点
- http 请求转发服务器
- node之http.request
- Node.js如何使用代理发送request请求?
- Node中的HTTP请求
- HTTP 请求转发、重定向
- java web http请求转发
- 请求转发(request)和重定向(response)
- 使用getNamedDispatcher()转发请求
- Request —— 让 Node.js http请求变得超简单
- BigDecimal用法详解
- a标签中有点击事件
- 【转】jQuery Lightbox 2 灯箱效果
- Laravel5.4 Unknown character set: 'utf8mb4'
- Java设计模式(二) 工厂方法模式
- node下使用request转发http请求
- [poj1185][NOI2001]炮兵阵地 状压dp
- A Windows service with the name MySQL already exists安装数据库出错
- 10.31日常总结
- Angular与模态框的通讯
- http协议学习-断点续传和多线程下载的实现原理
- Java--注解及反射读取注解
- 数据结构-算法
- Selenim IDE测试环境搭建