一家公司要求我做一项Angular任务。它们提供了以下说明,但API URL不起作用:
Create a single page angular application and use the following API to retrieve sports results and sort into a table of results that are displayed. Each sport result contains several data and always includes the publication time.
Method: POST
Content-Type: application/json
Url: https://ancient-wood-1161.getsandbox.com:443/results
Tasks:
-Display the sports results in reverse chronological order on the page.
-Add a filter to the page to display only certain types or events (e.g. f1Results)
-How can you confirm the code works?
-Bonus: Implement the rest call asynchronously您现在可以单击URL,并看到它不工作-它返回https://ancient-wood-1161.getsandbox.com:443/results,在角度上它给我一个标准的CORS错误。
我要求公司发送一个工作URL和/或更新API以接受来自任何地方的请求。他们的反应是:*guy's name* confirmed it worked. It is a post and the content type is json.
您能使用POST请求来处理GET数据吗?
发布于 2022-02-11 21:19:07
绝对一点儿没错。例如,您的avg请求返回一个访问令牌。它将是一个POST,因为POST也比获得更多的安全性,因为有效负载在正文中而不是URL字符串中。
至于他们的借口不起作用,试试邮递员,看看是否还会发生同样的问题。如果它仍然问他们,他们在哪里测试他们的API,就好像它在prem上一样,那么CORS就不会工作了。它很可能不是一家你想为之工作的公司。
发布于 2022-02-11 20:50:27
可以,停那儿吧。在某些情况下,这可能是必要的,因为GET不需要身体,而POST需要。这样你就可以绕过URL长度限制之类的问题了。
https://stackoverflow.com/questions/71086361
复制相似问题