Reputation: 11
public final class MyScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
MyScreen myScreen = new MyScreen();
String a = myScreen.getPage("http://www.google.com");
System.out.println("+++ "+a);
}
public void parse(String xml){
}
public String getPage(String url) {
String response = "";
try {
StreamConnection s = (StreamConnection)Connector.open(url);
InputStream input = s.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();
s.close();
} catch(Exception e) { }
return response;
}
}
This is the code I want to execute to get Http Contents in Blackberry. I got exception of StackOverflow. Please give me help with example.
Upvotes: 0
Views: 1006
Reputation: 11571
There is a BlackBerry developer guide - Code sample: Creating a connection over HTTP by using the first available transport - that will surely help you.
Upvotes: 0
Reputation: 28418
Just try searching on StackOverflow - there are a lot of info on this.
UPDATE:
Basically BB networking consists of 2 points:
Detecting what network transport to use. This is BB spesific. Have you heard about network transports? If not, then check Connecting your BlackBerry - http and socket connections to the world. Basically you end up with a url that is appended with a spesific string that tells to the BB internals what network transport to use.
Using HttpConnection
for the got url at step 1 to retrieve data from network. See the API docs on HttpConnection. There are sample code in there.
Upvotes: 3