code blackberry http client
HTTPClient is a small BlackBerry J2ME class that gets web content from a URL.
NO INTERNET CONNECTIVITY
If you can't get a connection to the internet (and have verified it by opening the browser on your BlackBerry simulator), then you probably need to start the MDS server. This is a .bat file in the simulator plugin path.
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
public class HTTPClient {
public static 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;
}
}
LINKSJ2ME Networking blog comments powered by Disqus
