还没有测试
String data = "Hello, World!"; // 要发送的数据
String url = "http://example.com/stream"; // 前台的URL地址
try {
// 创建一个URL对象并连接到前台的URL地址
URL urlObj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
// 设置请求方式和响应类型
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setContentType("application/octet-stream");
// 获取输入流并写入数据
OutputStream outputStream = conn.getOutputStream();
outputStream.write(data.getBytes());
outputStream.flush();
outputStream.close();
// 获取响应码并输出结果
int responseCode = conn.getResponseCode();
System.out.println("Response Code: " + responseCode);
conn.disconnect();