@Simon E
I don't understand: which REST implementation for Java are you using?
So, I just give you an example of using JAX-RS (Jersey implementation)
The server part (method of some REST class):
@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
public static Response upload(
@FormParam("name") String name,
@FormParam("content") String content)
throws Exception {
// NOTE: you get your content as String
// (do something here)
return Response.ok().build();
}
The client part (method of some JUnit test):
@Test
public void uploadFile()
throws Exception {
String address = "http://0.0.0.0:8000/r/upload";
WebResource r = Client.create().resource(address);
Form form = new Form();
form.add("name", "test");
form.add("content", "SOME CONTENT GOES HERE");
String s = r.post(String.class, form);
System.out.println(s);
}
That's it !!!
In case you have trouble with imports:
Server needs javax.ws.rs.* and javax.ws.rs.core.*
Client needs com.sun.jersey.api.client.* and
com.sun.jersey.api.representation.*
In any way, I would give you the advice to use JAX-RS rather than
alternative implementations, because JAX-RS will be part of the
upcoming Java EE 6