WishMeLz

生活其实很有趣

使用request后台发送请求

处理有跨域的接口。后台调用

const request = require('request');

router.get("/wnl", (req, res) => {
    request('https://www.sojson.com/open/api/lunar/json.shtml', function(error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body) // Show the HTML for the baidu homepage.
        } else {
            console.log(response, body);

        }
    })
})

request({
    url: url,
    method: "POST",
    json: true,
    headers: {
        "content-type": "application/json",
    },
    body: JSON.stringify(requestData)
}, function(error, response, body) {
    if (!error && response.statusCode == 200) {
    }
});