javascript - 403 响应代码 - 使用 Cowin setu API 时请求被阻止

标签 javascript node.js express amazon-cloudfront rest

我只是想在 nodejs 中使用 Cowin Setu API(印度)发出 covid 疫苗警报。但是我遇到了一些奇怪的事情,每当我点击获取请求时,我都会从云端收到 403 响应代码,显示“请求被阻止”,但 postman 和浏览器也是如此。请帮助我
收到此错误:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: Q1RZ94qgFp6AjUUKE4e9urMB85VejcqMbaJO6Y8Xq5Qp4kNjDBre9A==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

这是我的nodejs代码:
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
const axios = require("axios");
const { Telegram } = require("telegraf");
const fetch = require("node-fetch");
var cors = require('cors');
var request=require('request');


const tg = new Telegram(process.env.BOT_TOKEN);
const bot = new Telegram(process.env.BOT_TOKEN, {
polling: true
});

//bot.start((ctx) => ctx.reply('Welcom to Covid Vaccine Finder'))

/*bot.hears("about", ctx => {
ctx.reply("Hey, I am CoviBot!");
});
bot.launch();*/

app.use(bodyParser.json());

app.use(cors());



app.use(
bodyParser.urlencoded({
extended: true
})
);

app.get("/", function(req, res) {
res.send("Welcom to Covid Vaccine Finder");
});

app.get("/test", function(req, res, next) {
var d = new Date();
var options = {
year: "numeric",
month: "2-digit",
day: "2-digit"
};

var date = String(d.toLocaleDateString("en", options));
date = date.replace(/\//g, "-");
console.log(date);

const URL =
"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPinpincode=110088&date=13-05-2021";

var options = { 
url: URL,
method: 'GET',
headers: {
  'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'en-GB,en;q=0.8,en-US;q=0.6,hu;q=0.4',
    'Cache-Control': 'max-age=0',
    Connection: 'keep-alive',
    Host: 'cdn-api.co-vin.in',
    'User-Agent': 'request',


 }
 };
 request(options,function(err,res,body){
  let json = body;
 console.log(json);
 });


const txt = "Finding vaccine centres for you....";
//tg.sendMessage(process.env.GROUP_ID, txt);
res.send(txt);


});



 // Finally, start our server
 app.listen(process.env.PORT, function() {
 console.log("Covid app listening on port 3000!");
 });
希望这个问题能解决
谢谢

最佳答案

我添加了 user-agent请求的 header ,以便 API 识别我的请求来自浏览器,而不是脚本。

headers = {
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
}
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=303&date="+date
response = requests.get(url, headers=headers)

关于javascript - 403 响应代码 - 使用 Cowin setu API 时请求被阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67498285/

相关文章:

javascript - JCrop,如何清除所有div 宽度/高度标记?

javascript - 如何在不重启的情况下更新服务器的内容? (node.js)

javascript - Sequelize如何使用关联表?

node.js - 如何使用 React Router 从 React.js 的子路径修复错误的代理重定向?

javascript - 使用 Mongoose 通过 EJS 发送 DELETE 请求

node.js - 带有 expressjs 和 SSL p7b 证书的 nodejs

javascript - 我需要了解良好的 javascript 才能使用 jquery 吗?

javascript - 测试 Firebase 连接是否成功

PHP、Javascript JSON、XSS 保护

node.js - 无法使用Azure数据库进行繁琐的操作