1

I am trying to send a zip file as binary via HTTP request, When I do a call setting the Postman's tab as Binary then it works as I want to:

enter image description here

But when I try to send the same file as binary and use the option "RAW" then it does not work.I've tried to convert the zip into a binary in Java with the below code:

    try {
        StringBuilder sb = new StringBuilder();
        File file = new File(filePath);
        DataInputStream input = new DataInputStream( new FileInputStream( file ) );
        try {
            while( true ) {
                sb.append( Integer.toBinaryString( input.readByte() ) );
                //10100001001011111001010000010000101111111111111111111111111111111100101101010101100100111111111111111111111111111001110101100111111111111111111111111110110011101000010000001000000111010011001011110011111010010111011101001111000111010010101110010011011011011101001001110101110000110000100010100001001011110111110101000001000010111111111111111111111111111111110010110101010110010011111111111111111111111111100111010110011111111111111111111111111011001110100001000000100001001000000000100000000000011101001100101111001111101001011101110100111100011101001010010000000000101100001011001101100100010111101111011011111111111111111111111111011001110110011011001000101111011110110111111111111111111111111110110011111111111111111111111111101110101111111111111111111111111011011111111111111111111111111111101110100110111101101111111111111111111111111101100111010000100101110111000001010101101000011000000000
            }
        } catch( EOFException eof ) {
        } catch( IOException e ) {
            e.printStackTrace();
        }
        System.out.println(sb.toString());
    } catch( FileNotFoundException e2 ) {
        e2.printStackTrace();
    }

The message is being receiving with a different size and it is not the content I am expecting:

enter image description here

Can you tell me how I can send it as binary using the tab raw?

TulioVargas
  • 137
  • 1
  • 5
  • 2
    If you want to send something as binary then don't convert it to a string – ControlAltDel Dec 22 '22 at 19:52
  • Don't use Data Input/Output streams – ControlAltDel Dec 22 '22 at 19:52
  • Incidentally that's wrong on another count too: you can't use `Integer.toBinaryString` as its output is of variable length, so you wouldn't know how to decode it if you just appended its output over and over. Java has an HttpClient API, which you can use to do uploads – g00se Dec 22 '22 at 23:48

0 Answers0