[Java] URLConnection.setRequestProperty()/ URLConnection.getOutputStream()問題

如果要Send一個HTTP POST request去一個Server,用URLConnection.setRequestProperty()或 URLConnection.getOutputStream(),兩者有咩分別?

例如用URLConnection.setRequestProperty()的話:
  1. conn.setRequestProperty("method", "POST");
  2. conn.setRequestProperty("header", "Content-type: application/x-www-form-urlencoded\\r\\n"+ "Content-length: 1234\\r\\n");
  3. conn.setRequestProperty("content", data);
複製代碼
比起下面用URLConnection.getOutputStream():
  1. conn.setDoOutput(true);
  2. OutputStreamWriter streamWriter = new OutputStreamWriter(conn.getOutputStream());
  3. streamWriter.write(data);
  4. streamWriter.flush();
複製代碼
兩者有何分別?

謝謝。