【发布时间】:2021-10-04 16:25:47
【问题描述】:
我正在尝试限制客户端可以向使用 Azure 翻译 API 的翻译服务发出的请求数量。
以下来自 Microsoft 的链接描述了如何限制请求,但不清楚应在请求中的何处添加此限制信息。我假设请求标头?
https://docs.microsoft.com/en-us/azure/api-management/api-management-sample-flexible-throttling
这是卷曲。请注意末尾的速率限制标头。是这样的吗?
// Pass secret key and region using headers to a custom endpoint
curl -X POST " my-ch-n.cognitiveservices.azure.com/translator/text/v3.0/translate?to=fr" \
-H "Ocp-Apim-Subscription-Key: xxx" \
-H "Ocp-Apim-Subscription-Region: switzerlandnorth" \
-H "Content-Type: application/json" \
-H "rate-limit-by-key: calls=10 renewal-period=60 counter-key=1.1.1.1" \
-d "[{'Text':'Hello'}]" -v
【问题讨论】:
-
应在服务器上进行速率限制。你为什么要让客户端(curl)决定应该如何进行速率限制?
-
我用 PHP 做 curl 服务器端。我想随请求一起发送客户端的 IP,以便让 Azure 继续跟踪速率限制,因此我不必使用数据库。我使用了这个 CURL 示例来使其更易于查看,而不是使用我的 PHP 代码。
标签: javascript azure curl translation throttling