NVPair credentials = getCredentials(url);
if (credentials != null)
{
conn.addBasicAuthorization(null, credentials.getName(), credentials.getValue());
}
HTTPResponse resp = null;
if (entity != null)
{
HttpOutputStream stream = new HttpOutputStream();
resp = conn.Post(url.getFile(), stream, headerPairs);
byte[] buf = new byte[1024];
int r = -1;
while ((r = entity.read(buf)) != -1)
{
stream.write(buf, 0, r);
}
stream.close();
}
else
{
resp = conn.Post(url.getFile(), (NVPair[])null, headerPairs);
}
if (resp.getStatusCode() >= 300)
{
if (LOG.isDebugEnabled())
{
// Do not read data if debug is off.
// Client may get empty response, may not read stream twice.
LOG.debug("POST. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
byte[] data = resp.getData();
if (data != null)
{
LOG.debug("POST. Text : " + new String(data));
}
}