I need to send a binary message which is divided to 2 parts:
- The first part is 4 bytes and it has some information (say an integer)
- The second part has an XMLtext stream.
I have never done something like this before, how can I do this?
My code is something like this:
public String serverCall(String link, String data){
HttpURLConnection connection;
OutputStreamWriter writer = null;
URL url = null;
String parameters = data;
try
{
url = new URL(link);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestMethod("POST");
writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(parameters);
writer.flush();
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
How do I set the XML to be 4 bytes and how do I have 4 bytes of text before it?