2015-08-14 67 views
1

我有以下的基本結構: enter image description here火力地堡響應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(); 
       } 
      } 
     } 

    } 


} 
+0

你最終找到這個答案? – Rbar

回答

1

我希望我有足夠的聲譽分,只是發表評論= P,但我相信,爲什麼你得到400的原因是因爲你不發送您的數據傳輸到右端點。嘗試從URL剝離.json

https://<TEST-BASE>.firebaseio.com/articles?auth=<TOKEN>

+0

java.io.IOException:服務器返回的HTTP響應代碼:403 – Tony