Question

So I have a class Workout that I created and I would like to send it to a server using HttpPost. Is there a way I could add that class to a MultipartEntity or how should I post it?

Was it helpful?

Solution

First your class must implement java.io.Serializable.

        MultipartEntity e = new MultipartEntity();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(yourserializableobject);
        oos.flush();
        oos.close();
        InputStreamBody isb = new InputStreamBody(new ByteArrayInputStream(baos.toByteArray()), "o");
        e.addPart("o", isb);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top