HTTP方法POST和GET在Microsoft的Text-to-Speech REST API中的区别让您感到困惑。

huangapple go评论64阅读模式
英文:

Confused about the difference between HTTP methods POST and GET in Microsoft's Text-to-Speech REST AP

问题

我正在研究来自Microsoft的Text-to-Speech REST API,并对HTTP方法POST和GET之间的区别感到困惑。

该API有一个允许你获取访问令牌的终结点。我不确定为什么使用的是POST而不是GET方法。似乎你正在获取一个访问令牌,而不是创建一个新资源(POST)。

类似的问题出现在将文本转换为语音时。似乎你正在获取一个音频输出,而不是创建一个新资源(POST)。

获取声音列表似乎需要使用GET方法!

英文:

I'm looking into the Text-to-Speech REST API from Microsoft and am confused about the difference between HTTP methods POST and GET.

The API has an endpoint that lets you get an access token. I'm not sure why the HTTP method used is POST and not GET. It seems like you are GETing an access token, instead of creating a new resource (POST).

Similar question when converting text to speech. It seems like you are GETing an audio output, instead of creating a new resource (POST).

Seems like GETing a list of voices requires you to use a GET method!

答案1

得分: 1

身份验证令牌的认证请求通常以HTTP POST方式进行,有两个主要原因。

安全性:当用户提交他们的用户名和密码时,这些敏感信息不应包含在HTTP GET请求的URL或查询参数中。如果请求被拦截,凭据可能会受到威胁。另一方面,HTTP POST请求允许数据被发送到请求体中,这在URL或查询参数中不可见。

幂等性:HTTP GET请求应该是幂等的,这意味着多个相同的请求应该与单个请求具有相同的效果。身份验证请求不是幂等的,因为它们会导致创建新的会话或令牌,因此使用非幂等的HTTP POST请求更有意义。

英文:

Authentication requests for tokens typically happen over HTTP POSTs for 2 main reasons.

Security: When a user submits their username and password, this sensitive information should not be included in the URL or query parameters of an HTTP GET request. If the request is intercepted, the credentials could be compromised. HTTP POST requests, on the other hand, allow the data to be sent in the request body, which is not visible in the URL or query parameters.

Idempotence: HTTP GET requests should be idempotent, meaning that multiple identical requests should have the same effect as a single request. Authentication requests are not idempotent since they result in the creation of a new session or token, so it makes more sense to use a non-idempotent HTTP POST request.

huangapple
  • 本文由 发表于 2023年5月13日 07:36:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76240480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定