1 package de.j32.httplib;
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.io.OutputStreamWriter;
8 public class HttpPOSTRequest extends HttpRequest
10 boolean multipart_ = false;
11 static final String separator_ = "----MultiPartFormData--MultiPartFormData--MultiPartFormData----";
13 public HttpPOSTRequest(String url)
16 setContentType("application/x-www-form-urlencoded; charset=utf-8");
19 public HttpPOSTRequest setMultipart(boolean flag)
23 setContentType("multipart/form-data; boundary=" + separator_);
25 OutputStream body = body();
26 body.write("--".getBytes());
27 body.write(separator_.getBytes());
28 body.write("\r\n".getBytes());
30 catch (IOException e) {
31 throw new AssertionError(
32 "ByteArrayOutputStream throwing IOExcpetion");
39 public HttpRequest addParameter(String name, byte[] value, String encoding)
43 OutputStream body = body();
44 body.write("Content-Disposition: form-data; name=\"".getBytes());
45 body.write(name.getBytes());
46 body.write("\"\r\n".getBytes());
47 body.write("Content-Type: text/plain; charset=".getBytes());
48 body.write(encoding.getBytes());
49 body.write("\r\n".getBytes());
50 body.write(("Content-Length: " + value.length).getBytes());
51 body.write("\r\n\r\n".getBytes());
53 body.write("\r\n--".getBytes());
54 body.write(separator_.getBytes());
55 body.write("\r\n".getBytes());
58 // Encoding not really relevant here since url-encoding is plain
60 Writer writer = new OutputStreamWriter(body(), "ascii");
61 appendParameter(writer, body().size() == 0, name, value);
65 catch (IOException e) {
66 throw new AssertionError(
67 "ByteArrayOutputStream throwing IOExcpetion");