我需要使用json读取基于税项识别的信息https://wl-api.mf.gov.pl/api/search/nip/5250007738?date=2020-02-13
还有工作代码示例
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个请求。但是,使用Web浏览器我可以不受任何限制。有什么办法可以绕过429个限制?
您可以通过欺骗IP或用户代理来绕过此限制,但实际上不应该。
如果服务器的API限制为每天10个请求,则应遵守此限制。如果这是您的服务器,那么可以跳过它。但是,由于它不是您的服务器/ API,请遵守其规则。
有关429错误的更多信息:https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429