我试图使用HTTP POST将一些数据发送到服务器。
服务器希望在 $_POST['file'] 中收到二进制数据。
URL url = new URL("http://example.com");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStream outputStream = connection.getOutputStream();
outputStream.write("file=".getBytes());
//byte[] buffer contains the data
outputStream.write(buffer);
outputStream.close();
OutputStream.write方法是否是正确的写入流的方式?我需要处理除了缓冲区之外的字符串(“file =”)吗?