当前位置: 首页 > news >正文

杭州规划建设网站oppo软件商店app下载

杭州规划建设网站,oppo软件商店app下载,重庆好的网站制作公司,网络营销成功案例有哪些2022问题描述 使用Azure API Management, 想对一些固定的IP地址进行访问次数的限制#xff0c;如被限制的IP地址一分钟可以访问10次#xff0c;而不被限制的IP地址则可以无限访问#xff1f; ChatGPT 解答 最近ChatGPT爆火#xff0c;所以也把这个问题让ChatGPT来解答#x…问题描述 使用Azure API Management, 想对一些固定的IP地址进行访问次数的限制如被限制的IP地址一分钟可以访问10次而不被限制的IP地址则可以无限访问 ChatGPT 解答 最近ChatGPT爆火所以也把这个问题让ChatGPT来解答然后人工验证它的回答正确与否 根据对APIM Policy的文档参考 choose 和 rate-limit 策略组合理论上的确可以实现要求, 接下来就让我们实际验证 choose策略Azure API 管理策略参考 | Azure Docs choose 策略根据布尔表达式的求值结果应用括住的策略语句类似于编程语言中的 if-then-else 或开关构造。rate-limit策略Azure API 管理策略参考 | Azure Docs  rate-limit 策略可以对调用速率进行限制使每个指定时段的调用不超出指定的数目避免单个订阅的 API 使用量暴增。 超过调用速率时调用方会收到 429 Too Many Requests 响应状态代码。 验证步骤 1在API的Inbound 策略中添加 choose策略 策略具体内容见文末 2) 测试验证连续对该API访问10次以上得到429 Too Many Requests错误 3以上证明ChatGPT针对这个问题的解答是正确的 工程师解答 在参考ChatGPT给出的 choose rate limit 组合后我们也发现另一个选项。使用 rate-limit-by-key 策略实现对特定IP的速率限制。 rate-limit-by-key 策略Azure API 管理策略参考 | Azure Docs  可以对调用速率进行限制使指定时段的调用不超出指定的数目避免单个密钥的 API 使用量暴增。 密钥的值可以是任意字符串通常使用策略表达式来提供密钥。 可以添加可选增量条件指定在决定是否到达限制值时应该进行计数的请求。 超过此调用速率时调用方会收到 429 Too Many Requests 响应状态代码。 在官方文档中给出的示例中是针对所有的IP(context.Request.IpAddress)都进行了10次/60秒请求的限制而本示例中则特指“某些固定IP”限制。那么如何来完成这个需求呢 答案 就在“rate-limit-by-key 策略”的说明中”可以添加可选增量条件指定在决定是否到达限制值时应该进行计数的请求”, 所以只要可选增量条件(increment-condition) 的值根据输入的IP地址动态赋值True/False 就能完美匹配以上要求。 理论推断只需要实现如下逻辑即可以实现终极需求“想对一些固定的IP地址进行访问次数的限制如被限制的IP地址一分钟可以访问10次而不被限制的IP地址则可以无限访问” 只需两步: 1通过设置一个变量(set-variable) 值用C#代码来计算变量值在赋值语句中预先定义一个IP限制列表通过 contains 检查当前请求IP是否在列表中返回True or False 。True表示当前请求的IP需要速率限制, 否则不需要。 2 然后在rate-limit-by-key 的 increment-condition条件中使用上一步参数值进行判断是否计入限制 验证步骤 1在API的 Inbound 策略中添加 rate-limit-by-key策略 策略具体内容见文末 2验证在30秒访问5次以上后同样得到429 Too Many Requests错误 3) 当在请求Headers中添加Ocp-Apim-Trace: true 和 Ocp-Apim-Subscription-Key: {订阅Key}后可以查看请求在APIM中执行的日志跟踪。可以查看rate-limit-by-key 策略的执行情况. 总结 想实现固定IP地址访问次数的限制至少有如下两种解决方案。 方案一Choose rate-limit 策略组合 !--IMPORTANT:- Policy elements can appear only within the inbound, outbound, backend section elements.- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the inbound section element.- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the outbound section element.- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.- To remove a policy, delete the corresponding policy statement from the policy document.- Position the base element within a section element to inherit all policies from the corresponding section element in the enclosing scope.- Remove the base element to prevent inheriting policies from the corresponding section element in the enclosing scope.- Policies are applied in the order of their appearance, from the top down.- Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope. -- policiesinboundbase /set-variable nameIsCountIpLimit value{string ipAddress context.Request.IpAddress; Liststring cidrList new Liststring(){167.xxx. xxx.135,167.xxx. xxx.136,167.xxx. xxx.137};return cidrList.Contains(ipAddress);} /choosewhen condition((bool)context.Variables[IsCountIpLimit])rate-limit calls10 renewal-period60 //when/choose/inboundbackendbase //backendoutboundbase //outboundon-errorbase //on-error /policies 方案二rate-limit-by-key策略 !--IMPORTANT:- Policy elements can appear only within the inbound, outbound, backend section elements.- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the inbound section element.- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the outbound section element.- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.- To remove a policy, delete the corresponding policy statement from the policy document.- Position the base element within a section element to inherit all policies from the corresponding section element in the enclosing scope.- Remove the base element to prevent inheriting policies from the corresponding section element in the enclosing scope.- Policies are applied in the order of their appearance, from the top down.- Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope. -- policiesinboundbase /set-variable nameIsCountIpLimit value{string ipAddress context.Request.IpAddress; Liststring limitIPs new Liststring(){167.xxx. xxx.135,167.xxx. xxx.136,167.xxx. xxx.137};return limitIPs.Contains(ipAddress);} /rate-limit-by-key calls5 renewal-period30 counter-key(context.Request.IpAddress) increment-condition(context.Response.StatusCode 200 context.Response.StatusCode 300 (bool)context.Variables[IsCountIpLimit]) //inboundbackendbase //backendoutboundbase //outbound on-errorbase //on-error /policies
http://www.hkea.cn/news/14488953/

相关文章:

  • 四川移动端网站建设公众号平台登录入口官网
  • 加强网站微信信息编辑队伍建设哪些网站的简历做的比较好
  • 网站如何做淘宝客qq中心官方网站
  • 加强网站基础建设韶关企业网站建设公司
  • 青白江建设网站中国纪检监察报app下载
  • 建站流程流量最大的网站
  • 济南建设网站的公司哪家好邢台信息港聊天室
  • 网站图片代码怎么做的佛山小程序制作公司排行
  • 个人如何做短视频网站梧州外贸网站推广设计
  • 新乡网站建设服务大学生毕业设计网站
  • 企业微站系统网页升级紧急通知域名
  • 网站收录500多页东莞百姓网招聘
  • 电脑网站怎么做建e网全景图
  • 建网站要多少费用企业宣传片制作多少钱
  • 企业移动网站建设多行业品牌企业公司网站模板
  • 单页网站seo优化前端需要学什么语言
  • 上海网站备案审核时间奢侈品网站排名
  • 网站开发手机销售网站用例图动易手机网站模板
  • 深圳市建设主管部门门户网站外贸做企业什么网站
  • 手机建站系统北京网站建设华网天下科技
  • 如何降低网站的权重如何做网站的seo
  • 太原网站建设51sole通城网站建设
  • 高端建站设计做网站需要会什么编程
  • 如何进入一个网站开发人员工具安徽安庆天气
  • 上海公司网站建设东营市住房和城乡建设局网站
  • 做网站还要什么认证吗php网站开发报告
  • 网站速度慢的原因公司的官网建设
  • 重庆网站建设解决方案及流程网站建设横幅
  • 网站建设自网站建设费用报价
  • 网站开发 wenzhoudw做网站怎么替换字体