PDA

View Full Version : Please help about HttpConnection


susanta
03-18-2008, 10:11 AM
Hi all,

I am facing a typical problem about HttpConnection() for BlackBerry.But it is working fine in all other devices except BlackBerry.Bellow is the code:


public synchronized String getResponse(String sRequest)
{
String sReturn = null;
HttpConnection c = null;
java.io.InputStream is = null;
StringBuffer sb = new StringBuffer();
int ch;
int rc;
try {
sRequest=sRequest.trim();
c = (HttpConnection) Connector.open(sRequest);
c.setRequestProperty("User-Agent", System.getProperty("microedition.profiles"));
c.setRequestProperty("Content-Type", "application/octet-stream");
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
return null;
}
is = c.openInputStream();
while ((ch = is.read()) != -1) {
sb.append((char)ch);
}
is.close();
c.close();
sReturn = sb.toString();
} catch(Exception e) {
System.out.println("URLCatch : "+sRequest);
sReturn = null;
}
return sReturn ;
}


Please tell me what is the wrong inside this connection method? Why this is not establishing the connection in BlackBerry? Should i have to change anything in this method for BlackBerry?I tried a lot but colud not solve.
Please help.
Thanks in advance

susanta
03-18-2008, 10:27 AM
Sorry for one thing,
in the previous method,
"sRequest" is a simple URL String without any WAPGatewayIP & WAPGatewayAPN