1) call setDoOutput(true) before send content
2) you need to connect before you can send anything (so to answer your question in the code no that isn't on the correct location)
3) Also not sure why would you need to wrap the outputstream, you can already write bytes without wrapping
Code:
public void connect() {
final URL url = new URL("myserveraddress");
final byte[] message = "someMessage".getBytes(); // Any byte[] - will be a file one day
HttpURLConnection connection = url.openConnection();
connection.setRequestMethod("GET"); // other methods - same result
connection.setDoOutput(true);
//Actually connect
connection.connect();
// Write message
OutputStream out = connection.getOutputStream();
out.write(message);
out.flush();
out.close();
// Get response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = null;
while((line = in.readLine()) != null) {
System.out.println(line); // Prints the whole server response as expected
}
in.close();
}