0

我需要使用来自https://wl-api.mf.gov.pl/api/search/nip/5250007738?date=2020-02-13的 json 读取基于税务识别的信息

并且有工作代码示例

 private static void Main()
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            Log("NIP: ");
            string nip = Console.ReadLine();

            string date = DateTime.Now.ToShortDateString();
            string url = "https://wl-api.mf.gov.pl/api/search/nip/{0}?date={1}";
            string fullUrl = string.Format(url, nip, date);

            var get = Get(fullUrl);

            RootObject account = JsonConvert.DeserializeObject<RootObject>(get);
            if (account != null)
                Log("Status: " + account.result.subject.statusVat);

            Log("Press any key to continue...");


            Console.ReadKey();
        }

        public static string Get(string url)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                using (Stream stream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
            catch (Exception err)
            {
                Log(err.Message);
            }
            return string.Empty;
        }

        static void Log(string msg)
        {
            Console.WriteLine(msg);
        }

但是 API 有一些限制,我每天只能收到 10 个请求。但是,使用网络浏览器我可以不受任何限制地获得它。有没有办法绕过429限制?

4

1 回答 1

0

您可以通过欺骗您的 IP 或用户代理来绕过此限制,但您确实不应该这样做。

如果服务器的 API 限制是每天 10 个请求,您应该遵守此限制。如果这是您的服务器,当然,您可以绕过它。但是,由于它不是您的服务器/API,请遵守其规则。

有关 429 错误的更多信息:https ://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429

于 2020-02-13T14:57:54.840 回答