I am able to do a POST of a parameters string. I use the following code:

String parameters = "firstname=john&lastname=doe";

URL url = new URL("http://www.mywebsite.com");

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

connection.setDoOutput(true);

connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

connection.setRequestMethod("POST");

OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());

out.write(parameters);

out.flush();

out.close();

connection.disconnect();

However, I need to do a POST of binary data (which is in form of byte[]).

Not sure how to change the above code to implement it.

Could anyone please help me with this?

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐