一家公司要我做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并查看它不起作用 - 它回傳{"errors":[{"message":"Error processing request"}]}并且在 Angular 中它給了我一個標準的 CORS 錯誤。
我要求公司發送一個有效的 URL 和/或更新 API 以接受來自任何地方的請求。他們的回應是:
*guy's name* confirmed it worked. It is a post and the content type is json.
您可以使用資料POST請求嗎?GET
uj5u.com熱心網友回復:
絕對地。以您的 avg Login Request 為例,它回傳一個訪問令牌。它將是一個 POST,因為 POST 也比 GET 具有更高的安全性,因為有效負載位于正文而不是 URL 字串中。
至于他們的借口它不起作用,請在郵遞員中嘗試,看看是否仍然存在相同的問題。如果它仍然存在,那么詢問他們在哪里測驗了他們的 API,就好像它是在 prem 一樣,那么 CORS 不會起作用。它很可能不是您想為之作業的公司。
uj5u.com熱心網友回復:
是的你可以。在某些情況下,這可能是必要的,因為 GET 不接受正文,而 POST 接受。因此,它可以讓您繞過 URL 長度限制等問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/434117.html
標籤:javascript 有角度的 打字稿 休息 网址
上一篇:帶問號的URL格式
