我期待在這裏的文檔:http://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html如何設置一個URL連接,POST
,我沒有看到一個選項,以標誌作爲一個POST方法的請求。我期望看到.setRequestMethod("POST");
什麼的。我在看錯文檔嗎?
我正在使用Android 4.2和Java 1.6。雖然我不確定javase/1.4.2
是我應該找的。
URL url = new URL(this.getUrl());
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);
現在要做'connection.getOutpuStream()'和寫入它已經更多的選擇(然後記得'接近()'),和POST將被髮送。 –