Firebase REST API Java(不是 Android)。我得到的是 HTML 文本而不是我的数据库值
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从实时数据库的 REST API 读取,URL 必须以
.json
结尾。因此:To read from the REST API of the Realtime Database, the URL must end in
.json
. So:Also see the Firebase documentation on getting started with the REST API: