X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Fhttplib%2FHttpPOSTRequest.java;h=d9ae78e6ed5920c647475b94f0fc795e353e48c7;hb=e4126a1787b7045a53f6074e9ef15681c9f5fde4;hp=f59134eeba5b43fdeb3262145b42de2e73e1b919;hpb=276d9a69fa796728169c2992921a1e4bd875f549;p=jpim.git diff --git a/src/de/j32/httplib/HttpPOSTRequest.java b/src/de/j32/httplib/HttpPOSTRequest.java index f59134e..d9ae78e 100644 --- a/src/de/j32/httplib/HttpPOSTRequest.java +++ b/src/de/j32/httplib/HttpPOSTRequest.java @@ -5,66 +5,67 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -public class HttpPOSTRequest - extends HttpRequest +public class HttpPOSTRequest extends HttpRequest { - boolean multipart_ = false; - static final String separator_ = - "----MultiPartFormData--MultiPartFormData--MultiPartFormData----"; - - public HttpPOSTRequest(String url) - { - super(url, "POST"); - setContentType("application/x-www-form-urlencoded; charset=utf-8"); - } - - public HttpPOSTRequest setMultipart(boolean flag) - { - multipart_ = flag; - if (multipart_) { - setContentType("multipart/form-data; boundary=" + separator_); - try { - OutputStream body = body(); - body.write("--".getBytes()); - body.write(separator_.getBytes()); - body.write("\r\n".getBytes()); - } - catch (IOException e) { - throw new AssertionError("ByteArrayOutputStream throwing IOExcpetion"); - } - } - return this; - } - - @Override - public HttpRequest addParameter(String name, byte[] value, String encoding) - { - try { - if (multipart_) { - OutputStream body = body(); - body.write("Content-Disposition: form-data; name=\"".getBytes()); - body.write(name.getBytes()); - body.write("\"\r\n".getBytes()); - body.write("Content-Type: text/plain; charset=".getBytes()); - body.write(encoding.getBytes()); - body.write("\r\n".getBytes()); - body.write(("Content-Length: " + value.length).getBytes()); - body.write("\r\n\r\n".getBytes()); - body.write(value); - body.write("\r\n--".getBytes()); - body.write(separator_.getBytes()); - body.write("\r\n".getBytes()); - } - else { - // Encoding not really relevant here since url-encoding is plain ASCII - Writer writer = new OutputStreamWriter(body(),"ascii"); - appendParameter(writer, body().size() == 0, name, value); - writer.flush(); - } - } - catch (IOException e) { - throw new AssertionError("ByteArrayOutputStream throwing IOExcpetion"); - } - return this; - } + boolean multipart_ = false; + static final String separator_ = "----MultiPartFormData--MultiPartFormData--MultiPartFormData----"; + + public HttpPOSTRequest(String url) + { + super(url, "POST"); + setContentType("application/x-www-form-urlencoded; charset=utf-8"); + } + + public HttpPOSTRequest setMultipart(boolean flag) + { + multipart_ = flag; + if (multipart_) { + setContentType("multipart/form-data; boundary=" + separator_); + try { + OutputStream body = body(); + body.write("--".getBytes()); + body.write(separator_.getBytes()); + body.write("\r\n".getBytes()); + } + catch (IOException e) { + throw new AssertionError( + "ByteArrayOutputStream throwing IOExcpetion"); + } + } + return this; + } + + @Override + public HttpRequest addParameter(String name, byte[] value, String encoding) + { + try { + if (multipart_) { + OutputStream body = body(); + body.write("Content-Disposition: form-data; name=\"".getBytes()); + body.write(name.getBytes()); + body.write("\"\r\n".getBytes()); + body.write("Content-Type: text/plain; charset=".getBytes()); + body.write(encoding.getBytes()); + body.write("\r\n".getBytes()); + body.write(("Content-Length: " + value.length).getBytes()); + body.write("\r\n\r\n".getBytes()); + body.write(value); + body.write("\r\n--".getBytes()); + body.write(separator_.getBytes()); + body.write("\r\n".getBytes()); + } + else { + // Encoding not really relevant here since url-encoding is plain + // ASCII + Writer writer = new OutputStreamWriter(body(), "ascii"); + appendParameter(writer, body().size() == 0, name, value); + writer.flush(); + } + } + catch (IOException e) { + throw new AssertionError( + "ByteArrayOutputStream throwing IOExcpetion"); + } + return this; + } }