猿问
下载APP

在ExpressJS中,怎么发送请求到别的服务器请求数据?

在ExpressJS中,怎么发送请求到别的服务器请求数据


喵喵时光机
浏览 254回答 1
1回答

慕慕森

var express = require('express');var router = express.Router();var request = require('request');router.all('/*', function(req, res){var method = req.method.toUpperCase();var proxy_url = 'http:www.xx.com/api';var options = {headers: {"Connection": "close"},url: proxy_url,method: method,json: true,body: req.body};function callback(error, response, data) {if (!error && response.statusCode == 200) {console.log('------接口数据------',data);res.json(data)}}request(options, callback);})
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答