使用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) {
    }
}); 

发表评论

电子邮件地址不会被公开。 必填项已用*标注