-1

I used to make the thhpput call by passing parameters like this picture httpput with param

now i want to to change with body binay methode like this picture httpput body binary

i found the solution in ios :

[request setHTTPBody: dataToUpload];

I need the solution in Android . thanks a lot

  • yes, as usual ... set content type, get output stream from http connection, copy file to the stream, close streams and that's it (it is not a multipartentity) – Selvin Jun 17 '16 at 11:15

1 Answers1

0

Well, you will have to set the appropriate content type, e.g application/octet-stream and the write your content to the connections output stream.

conn = (HttpURLConnection) url.openConnection(); 
conn.setDoOutput(true); // Allow Outputs
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/octet-stream");

outputStream = connection.getOutputStream();
outputStream.writeBytes(lineEnd);
outputStream.close();

This will transfer the raw binary data, if you want to upload a file, check https://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/

  • hehe why? why `DataOutputStream`? why do we need abstraction of `DataOutputStream` ? `connection.getOutputStream()` is `OutputStream` ... you can wrap it with some buffered stream but why `DataOutputStream`? – Selvin Jun 17 '16 at 11:20