Firebase REST API Java(不是 Android)。我得到的是 HTML 文本而不是我的数据库值

发布于 2025-01-09 09:10:39 字数 962 浏览 1 评论 0原文

我正在使用 Firebase 制作新的 REST API Java 项目。我在这里运行了我的代码:

URL url = new URL("https://restapi-example-java-default-rtdb.asia-southeast1.firebasedatabase.app/get");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();

conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type","application/json");
conn.setRequestProperty("Accept","application/json");
conn.setConnectTimeout(5000);
conn.setDoInput(true);

conn.connect();
System.out.println(conn.getResponseMessage());
int responseCode = conn.getResponseCode();
System.out.println(responseCode);

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
while ((inputLine = in.readLine()) != null) {
    outResult.append(inputLine);
}

System.out.println(outResult);

但是,我能得到的是某种关于 Google Login 的 html。 连接的响应消息和代码 OK 和 200;

我的火力规则:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

I was making my new REST API Java project with Firebase. I ran my code here:

URL url = new URL("https://restapi-example-java-default-rtdb.asia-southeast1.firebasedatabase.app/get");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();

conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type","application/json");
conn.setRequestProperty("Accept","application/json");
conn.setConnectTimeout(5000);
conn.setDoInput(true);

conn.connect();
System.out.println(conn.getResponseMessage());
int responseCode = conn.getResponseCode();
System.out.println(responseCode);

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
while ((inputLine = in.readLine()) != null) {
    outResult.append(inputLine);
}

System.out.println(outResult);

However, what I could get was some kind of html which was about Google Login.
Response Message and Code of the connection was OK and 200;

My firebase rule:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩虹直至黑白 2025-01-16 09:10:39

要从实时数据库的 REST API 读取,URL 必须以 .json 结尾。因此:

new URL("https://restapi-example-java-default-rtdb.asia-southeast1.firebasedatabase.app/get.json");
//

To read from the REST API of the Realtime Database, the URL must end in .json. So:

new URL("https://restapi-example-java-default-rtdb.asia-southeast1.firebasedatabase.app/get.json");
                                                                                          // ????

Also see the Firebase documentation on getting started with the REST API:

We can use any Firebase Realtime Database URL as a REST endpoint. All we need to do is append .json to the end of the URL and send a request from our favorite HTTPS client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文