小编Phi*_*p B的帖子

从Web服务器获取后,为什么我的二进制数据更大?

我需要通过在Python/Django中实现的Web服务来提供二进制文件.问题是,当我将原始文件与传输的文件与vbindiff进行比较时,我看到传输文件上的尾随字节,遗憾地使它无用.

二进制文件由客户端在Java中保存,具有:

HttpURLConnection userdataConnection = null;
    URL userdataUrl = null;
    try {
        userdataUrl = new URL("http://localhost:8000/app/vuforia/10");

        userdataConnection = (HttpURLConnection) userdataUrl.openConnection();
        userdataConnection.setRequestMethod("GET");
        userdataConnection.setRequestProperty("Content-Type", "application/octet-stream");
        userdataConnection.connect();

        InputStream userdataStream = new BufferedInputStream(userdataConnection.getInputStream());
        try (ByteArrayOutputStream fileStream = new ByteArrayOutputStream()) {
            byte[] buffer = new byte[4094];
            while (userdataStream.read(buffer) != -1) {
                fileStream.write(buffer);
            }
            byte[] fileBytes = fileStream.toByteArray();
            try (FileOutputStream fos = new FileOutputStream("./test.dat")) {
                fos.write(fileBytes);
            }
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

我认为HttpURLConnection.getInputStream只读取响应的主体,或不?

此代码用于后端中的数据

在views.py中: …

python java django byte file

0
推荐指数
1
解决办法
47
查看次数

标签 统计

byte ×1

django ×1

file ×1

java ×1

python ×1