Examples of HttpMultipart


Examples of org.apache.http.entity.mime.HttpMultipart

            writer.append("some random whatever");
        } finally {
            writer.close();
        }
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
                new FileBody(tmpfile));
        FormBodyPart p2 = new FormBodyPart(
                "field2",
                new InputStreamBody(new FileInputStream(tmpfile), "file.tmp"));
       
        multipart.addBodyPart(p1);
        multipart.addBodyPart(p2);
       
        multipart.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        multipart.writeTo(out);
        out.close();
       
        String expected = "\r\n" +
            "--foo\r\n" +
            "Content-Disposition: form-data; name=\"field1\"; " +
                "filename=\"" + tmpfile.getName() + "\"\r\n" +
            "\r\n" +
            "some random whatever\r\n" +
            "--foo\r\n" +
            "Content-Disposition: form-data; name=\"field2\"; " +
                "filename=\"file.tmp\"\r\n" +
            "\r\n" +
            "some random whatever\r\n" +
            "--foo--\r\n" +
            "\r\n";
        String s = out.toString("US-ASCII");
        assertEquals(expected, s);
        assertEquals(-1, multipart.getTotalLength());
       
        tmpfile.delete();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.