嗨,我想知道為什么我的 API 呼叫在瀏覽器中有效,但是在 Android Studio 中呼叫時出現 403 錯誤。除錯
D/OkHttp: <-- 403 https://api.boblop.com/search/api/rest/v3/catalog/products/search/keyword?q=asesea&key=esaesaesae (106ms)
D/OkHttp: server: AkamaiGHost
D/OkHttp: mime-version: 1.0
D/OkHttp: content-type: text/html
D/OkHttp: content-length: 350
D/OkHttp: expires: Tue, 20 Sep 2022 10:27:24 GMT
D/OkHttp: date: Tue, 20 Sep 2022 10:27:24 GMT
D/OkHttp: strict-transport-security: max-age=31536000 ; includeSubDomains
D/OkHttp: <HTML><HEAD>
D/OkHttp: <TITLE>Access Denied</TITLE>
D/OkHttp: </HEAD><BODY>
D/OkHttp: <H1>Access Denied</H1>
Any Ideas why android studio might be giving me back a 403 error?
Many Thanks
uj5u.com熱心網友回復:
HTTP 403 Forbidden client 錯誤狀態回應碼表示服務器理解請求但拒絕授權。
此狀態類似于 401,但在這種情況下,重新認證不會有任何區別。該訪問被永久禁止并與應用程式邏輯相關聯(如密碼錯誤)。
uj5u.com熱心網友回復:
我只是在一些代碼中實作它,你可以在下面檢查它:
request = new Request.Builder()
.url("https://api.johnlewis.com/search/api/rest/v2/catalog/products/search/keyword?q=dishwasher&key=AIzaSyDD_6O5gUgC4tRW5f9kxC0_76XRC8W7_mI")
.get()
.addHeader("Cache-Control","no-cache")
.addHeader("User-Agent",System.getProperty("http.agent"))
.build();
通過使用上面的代碼,我能夠在移動應用程式中獲得 200 回應。我為此使用了 OkttpClient,只需在改造中添加標頭即可解決 403 問題。
Response{protocol=h2, code=200, message=, url=https://api.johnlewis.com/search/api/rest/v2/catalog/products/search/keyword?q=dishwasher&key=AIzaSyDD_6O5gUgC4tRW5f9kxC0_76XRC8W7_mI}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/510564.html
標籤:安卓api科特林调试改造
上一篇:在顫振中使用標志
