【问题标题】:how to get fileinputstream bytes as octetstream?如何将文件输入流字节作为八位字节流?
【发布时间】:2016-02-19 09:30:31
【问题描述】:

嗨朋友们,我正在尝试发送一个帖子请求。在wireshark体内看起来是这样的

------WebKitFormBoundaryPGENMvyXR2Vt226r
Content-Disposition: form-data; name="csrf_token"

csrf:MxLfAIgtghMohbOWeEwFv11Ou8eedDFQO0NXw6DGcZC1w1hTDo1umrysYcxho6bX
------WebKitFormBoundaryPGENMvyXR2Vt226r
Content-Disposition: form-data; name="imagefilename"; filename="myFilemain.bin"
Content-Type: application/octet-stream

...qz...OO.M..g...`.:...../o.up.........G............y......f;....&Il..*..A.........0. E.fP.P------------------here is my bin file bytes---------------
..C.x...Q..J.._+%.. bla bla

但是当我在代码方面发帖时,它似乎是这样的:

------WebKitFormBoundaryPGENMvyXR2Vt226r
Content-Disposition: form-data; name="csrf_token"

csrf:MxLfAIgtghMohbOWeEwFv11Ou8eedDFQO0NXw6DGcZC1w1hTDo1umrysYcxho6bX
------WebKitFormBoundaryPGENMvyXR2Vt226r
Content-Disposition: form-data; name="imagefilename"; filename="myFilemain.bin"
Content-Type: application/octet-stream

²qz‹ÁOOõMÓâg‘Ç`:Êëá‡/oåupˆéìŒÛ.Ó‰G²¹²ƒö‘•®yñúÇ̰f;ª¥ŸÉ&Il³š*ÄAŞøØÄñŠ…¦0Ğ EfP½P
£¢CÓxÀQÃJ¥_+%ã—¢ÌGà¸,Öû¶­­a4ªW&Ú×zÇñg~5.    ³%FÀìDëÀ²tñş)Aéåf>¥jÀƒã8 ±šeH™Íäi“ktÇ   ‡0¢û³ımİp‘}à

------WebKitFormBoundaryPGENMvyXR2Vt226r--

如何将字节作为八位字节流获取

这是我的代码:

FileInputStream fis = null;
        try {

            fis = new FileInputStream(uploadFile);

            InputStreamReader inputStreamReader = new InputStreamReader(fis, "UTF-8");
            BufferedReader br = new BufferedReader(inputStreamReader);
            String line;
            while ((line = br.readLine()) != null) {
                builder.append(line.toCharArray());//stringBuilder
                System.out.println(line.toCharArray());
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

【问题讨论】:

    标签: file-upload http-post httpclient fileinputstream


    【解决方案1】:

    here是关于multiPart文件上传示例的一些信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 2020-04-09
      • 1970-01-01
      • 2011-10-14
      • 2020-07-09
      相关资源
      最近更新 更多