Wednesday, August 19, 2009

Get requested page from Http Connection java blackberry development

public static String getPage(String url)
{


String response = "";
try {
HttpConnection conn = (HttpConnection)Connector.open(url, Connector.READ_WRITE);
InputStream input =conn.openInputStream();
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
while( -1 != (len = input.read(data)))
{
raw.append(new String(data, 0, len));
}
response = raw.toString();
input.close();

} catch(Exception e)
{
Dialog.alert("Error");
}
return response;
}

No comments:

Post a Comment