sParams += aParams[p].getName()+"="+URLEncoder.encode(aParams[p].getValue(), "UTF-8");
if (p<aParams.length-1) sParams += "&";
} // next
} // fi
HttpURLConnection oCon = (HttpURLConnection) oUrl.openConnection();
oCon.setUseCaches(false);
oCon.setFollowRedirects(false);
oCon.setInstanceFollowRedirects(false);
oCon.setDoInput (true);
oCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
oCon.setRequestProperty("Content-Length", String.valueOf(sParams.getBytes().length));
oCon.setFixedLengthStreamingMode(sParams.getBytes().length);
oCon.setDoOutput(true);
oCon.setRequestMethod("POST");
OutputStreamWriter oWrt = new OutputStreamWriter(oCon.getOutputStream());
oWrt.write(sParams);
oWrt.flush();
oWrt.close();
int responseCode = oCon.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {
HttpRequest oMoved = new HttpRequest(oCon.getHeaderField("Location"), oUrl, "POST", aParams);
oRetVal = oMoved.post();
sUrl = oMoved.url();
} else if (responseCode == HttpURLConnection.HTTP_OK ||
responseCode == HttpURLConnection.HTTP_ACCEPTED) {
InputStream oStm = oCon.getInputStream();
String sEnc = oCon.getContentEncoding();
if (sEnc==null) {
ByteArrayOutputStream oBya = new ByteArrayOutputStream();
new StreamPipe().between(oStm, oBya);
oRetVal = oBya.toByteArray();
} else {
int c;
StringBuffer oDoc = new StringBuffer();
Reader oRdr = new InputStreamReader(oStm, sEnc);
while ((c=oRdr.read())!=-1) {
oDoc.append((char) c);
} // wend
oRdr.close();
oRetVal = oDoc.toString();
}
oStm.close();
} else {
throw new IOException(String.valueOf(responseCode));
}
oCon.disconnect();
return oRetVal;
} // post