My Code is as follows
PHP Code:
public synchronized bytexxx91;xxx93; sendPost(String strURL, bytexxx91;xxx93; xmlbuff) throws Exception {
// ShowDialog sh = new ShowDialog("inside transpport service: sendPost");
// ShowDialog.invokeLater(sh);
int status = 0;
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
Thread connThread;
connThread = Thread.currentThread();
ShowDialog sh;
bytexxx91;xxx93; bRet = null;
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
try {
c = (HttpConnection) Connector.open(strURL + URLs.sideKick);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(xmlbuff.length));
c.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, HttpProtocolConstants.CONTENT_TYPE_APPLICATION_XML);
c.setRequestProperty(HttpProtocolConstants.HEADER_CONNECTION, "KeepAlive");
////store in outputStream in chunks or bit by bit
if (xmlbuff != null) {
// int i = 0, len = 0;
// len = xmlbuff.length;
os = c.openOutputStream();
// while (i < len) {
os.write(xmlbuff);
os.flush();
// i++;
// }
/**
* the getResponseCode can flush the outputstream itself
*/
}
sh = new ShowDialog("HTTP POST: before responseCode() for URL: " + strURL);
ShowDialog.invokeLater(sh);
status = c.getResponseCode();
sh = new ShowDialog("HTTP POST: after responseCode() for URL: " + strURL);
ShowDialog.invokeLater(sh);
if (status == 200) {
sh = new ShowDialog("HTTP POST: Inside 200 :The Url: " + strURL + ":status: " + status);
ShowDialog.invokeLater(sh);
is = c.openDataInputStream();
baos2 = new ByteArrayOutputStream();
bytexxx91;xxx93; bt = new bytexxx91;1xxx93;;
while ((is.read(bt)) != -1) {
baos2.write(bt);
baos2.flush();
}
bRet = baos2.toByteArray();
return bRet;
} else {
sh = new ShowDialog("HTTP POST: Inside 200 else: The Url: " + strURL + ":status: " + status + ": not connected");
ShowDialog.invokeLater(sh);
}
} catch (Exception e) {
Prnt.println(e.toString() + ":" + getClass().toString() + ":post");
if (c != null) {
c.close();
c = null;
c = (HttpConnection) Connector.open(strURL + URLs.sideKick);
}
status = c.getResponseCode();
String curThread = null;
boolean tIsAlive;
if (connThread != null) {
tIsAlive = connThread.isAlive();
if (tIsAlive) {
curThread = "Alive";
} else {
curThread = "not Alive";
}
}
sh = new ShowDialog("The Url: " + strURL + ":status: " + status + ": Thread :" + curThread + ": connection error: " + e.toString());
ShowDialog.invokeLater(sh);
Prnt.logSpecificEvent("ERROR: HTTP POST URL :" + strURL + ":status: " + status + ": connection error: " + e.toString());
} finally {
try {
if (is != null) {
is.close();
}
if (c != null) {
c.close();
}
} catch (Exception e) {
Prnt.println(e.toString() + ":" + getClass().toString() + ":post");
}
}
return null;
}
I have the attachment from the etheral from the NetBeans build for BlackBerry application.
I am viewing in JDE version 4.5 and testing in BlackBerry 8100.
I have tried Connection:KeepAlive, but don't know how to send Connection: close
I have tried
Code:
mode=Connection.READ_WRITE;(HttpConnection)Connector.open(url,mode,false);
Both are not working
Regards