改造修改收到的服务器响应

问题描述 投票:0回答:2

我正在 newsApi 上使用改造。我正在尝试到达终点

https://newsapi.org/v2/sources?apiKey=xxxxx

如果 API 密钥服务器返回错误:

{"status":"error","code":"apiKeyInvalid","message":"Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key."}

如果没有 api 密钥服务器返回:

{“status”:“error”,“code”:“apiKeyMissing”,“message”:“Your API key is missing. Append this to the URL with the apiKey param, or use the x-api-key HTTP header.”}

但在我的应用程序中,改造在这两种情况下都会返回以下内容:

Response{protocol=http/1.1, code=401, message=Unauthorized, url=https://newsapi.org/v2/sources}

两种情况只是网址发生了变化,但消息和代码是相同的。

为什么 Retrofit 会修改服务器响应以及如何获取原始服务器消息或响应?

提前致谢。

android retrofit2
2个回答
0
投票

没有 api 密钥会使您未经授权,因此 Retrofit 访问错误正文并没有错误,请查看此之前的答案


0
投票

您必须登录 news.api,您必须拥有访问数据的帐户。

© www.soinside.com 2019 - 2024. All rights reserved.