Node.js之request模块 发送请求
2021-01-03 14:30
标签:上传 link save from class span ipa color content 导入 get 请求 post 请求 Node.js之request模块 发送请求 标签:上传 link save from class span ipa color content 原文地址:https://www.cnblogs.com/jcz1206/p/13640039.html
npm install request --save
@Get(‘/xxxxx‘)
async getImage(@Req() request: Request, @Res() response: Response) {
const url = request.query.url;
requestHttp(url).pipe(response);
}
application/x-www-form-urlencoded
requestHttp.post(url).form(request.body).pipe(response);
或者
requestHttp({
method : ‘post‘,
uri: url,
form: request.body
})
.pipe(response)application/json
requestHttp({
method : ‘post‘,
uri: url,
json: true,
headers: {
"content-type": "application/json",
},
body: request.body,
})
.pipe(response);
multipart/form-data
var formData = {
// Pass a simple key-value pair
my_field: ‘my_value‘,
// Pass data via Buffers
my_buffer: new Buffer([1, 2, 3]),
// Pass data via Streams
my_file: fs.createReadStream(__dirname + ‘/unicycle.jpg‘),
};
request.post({url:url, formData: formData}, function (error, response, body) {
if (!error && response.statusCode == 200) {
}
})
作者:袁峥
链接:https://www.jianshu.com/p/a156729ce499
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
下一篇:ADO.net很重要
文章标题:Node.js之request模块 发送请求
文章链接:http://soscw.com/index.php/essay/39837.html