我有以下的基本結構: 火力地堡響應400
,現在我想將一些數據添加到文章的節點。例如:
{"title":"Test","content":"Test text","keyWords":"1,2,3","date":"Aug 14, 2015 5:52:16 PM"}
Firebse REST API文檔中說,我應該張貼數據,但日誌寫入
服務器返回的HTTP響應代碼:400網址: https://開頭$ TEST-BASE .firebaseio.com/articles.json?auth = $ TOKEN
$TEST-BASE
和$TOKEN
是有效的參數。我可以清楚地看到GET響應。哪裏不對?代碼: 公共類JSONTest {
public static void main(String[] args) throws IOException {
post("{\"title\":\"Test\",\"content\":\"Test text\",\"keyWords\":\"1,2,3\",\"date\":\"Aug 14, 2015 5:52:16 PM\"}", "https://<TEST-BASE>.firebaseio.com/articles.json?auth=<TOKEN>");
}
private static void post(String json, String urlString) {
OutputStreamWriter out = null;
try {
URL url = new URL(urlString);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("POST");
out = new OutputStreamWriter(
httpCon.getOutputStream());
System.out.println(json);
out.write(json);
httpCon.getInputStream();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
你最終找到這個答案? – Rbar