Firebase REST API Java(不是 android)。我得到 HTML 文本而不是我的数据库值
Firebase REST API Java(Not android). I got HTML Texts instead of my database value
我正在使用 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);
但是,我能得到的是某种 html,大约是 Google 登录。
响应消息和连接代码正常,200;
我的 firebase 规则:
{
"rules": {
".read": true,
".write": true
}
}
要从实时数据库的 REST API 读取,URL 必须以 .json
结尾。所以:
new URL("https://restapi-example-java-default-rtdb.asia-southeast1.firebasedatabase.app/get.json");
//
另请参阅 getting started with the REST API 上的 Firebase 文档:
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.
我正在使用 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);
但是,我能得到的是某种 html,大约是 Google 登录。 响应消息和连接代码正常,200;
我的 firebase 规则:
{
"rules": {
".read": true,
".write": true
}
}
要从实时数据库的 REST API 读取,URL 必须以 .json
结尾。所以:
new URL("https://restapi-example-java-default-rtdb.asia-southeast1.firebasedatabase.app/get.json");
//
另请参阅 getting started with the REST API 上的 Firebase 文档:
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.