/** * Can be used to generate the XML request. * * @return the an input which can be used to generate an XML document which is sent to the URL * @throws IOException in case of an IO error while sending the XML document */ public XMLStructuredOutput getOutput() throws IOException { return new XMLStructuredOutput(outcall.getOutput()); }
/** * Sents the given context as POST to the designated server. * * @param params the data to POST * @param charset the charset to use when encoding the post data * @return the outcall itself for fluent method calls * @throws IOException in case of any IO error */ public Outcall postData(Context params, Charset charset) throws IOException { connection.setRequestMethod(REQUEST_METHOD_POST); connection.setRequestProperty(HEADER_CONTENT_TYPE, CONTENT_TYPE_FORM_URLENCODED); this.charset = charset; OutputStreamWriter writer = new OutputStreamWriter(getOutput(), charset.name()); StringBuilder sb = new StringBuilder(); boolean first = true; for (Map.Entry<String, Object> entry : params.entrySet()) { if (!first) { sb.append("&"); } first = false; sb.append(URLEncoder.encode(entry.getKey(), charset.name())); sb.append("="); sb.append(URLEncoder.encode(NLS.toMachineString(entry.getValue()), charset.name())); } writer.write(sb.toString()); writer.flush(); return this; }