[問題] get api一直回覆400 bad request

看板Ajax作者 (見習生_O7)時間3年前 (2020/11/26 15:37), 3年前編輯推噓0(006)
留言6則, 1人參與, 3年前最新討論串1/1
我目前在嘗試用第三方的API提供股票報價的資訊 有得到token跟網址,正常直接用瀏覽器get的時候,都能成功得到一個json格式的資料 但是不知道為什麼 改成用程式get,都會一直提示我400 bad request 我是用axios的get method,應該原理是跟瀏覽器差不多才對 不知道問題出在哪邊,想請各位指教 ps:我是自學的程式新手,可能有部分知識沒學全,所以問題可能比較基礎 https://iexcloud.io/ Sandbox token: https://sandbox.iexapis.com/stable/stock/TSLA/quote?token=Tpk_1f7ac84b1178430ba2db2dc2427cced9 https://i.imgur.com/rijVIC1.png
https://i.imgur.com/dXX1a4u.png
https://i.imgur.com/iu2t2rl.png
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.77.42.109 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1606376266.A.24D.html

11/26 21:11, 3年前 , 1F
主要是你 axios 的用法的問題,一般來說你的
11/26 21:11, 1F

11/26 21:11, 3年前 , 2F
baseURL 是要放你要串的 API 的網址的共同的前綴,
11/26 21:11, 2F

11/26 21:12, 3年前 , 3F
比如可能會放 https://sandbox.iexapis.com/ ,然後
11/26 21:12, 3F

11/26 21:12, 3年前 , 4F
你 get 那邊的網址就是扣掉 baseURL 後的部份
11/26 21:12, 4F

11/26 21:13, 3年前 , 5F
你的寫法變成是你在 get
11/26 21:13, 5F

11/26 21:13, 3年前 , 6F
https://sandbox.iexapis.com/ 而已,結果就是 400
11/26 21:13, 6F
哇,太感謝了 原本以為沒差,沒想到改了之後還真的可以了 ※ 編輯: jeffguoft (203.77.42.109 臺灣), 11/27/2020 00:41:21
文章代碼(AID): #1VlrjA9D (Ajax)