简体   繁体   English

nodejs route.get发送发帖请求

[英]nodejs route.get to SEND a post request

The get to this route works fine. 到达这条路线的工作正常。

But how do I take my route.get() and make it do a post? 但是,我该如何使用route.get()并使其发布? If the post is written in jquery, or express, or something else I don't care. 如果帖子是用jquery或Express编写的,或者其他无关紧要的内容。 Below I just used the jquery as an example. 下面我仅以jquery为例。

router.get('/', function (req, res, next) {
    var url = 'blabla'
    $.post('anotherBlaBla'
        , { app: url }
    );
});

You can use http client axios 您可以使用http客户端axios

Performing a POST request 执行POST请求

 var axios = require('axios');

 axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
 })
 .then(function (response) {
    console.log(response);
 })
 .catch(function (error) {
    console.log(error);
 });
const request = require('request');

var url = 'blabla';

request.post(
    url
    , { json: { api: url } }
    , function (err, res, bdy) {
        if (!err && res.statusCode == 200)
            console.log(bdy)
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM