質問

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?

役に立ちましたか?

解決

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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top