03-11-2011 12:46 AM
Hi,
I nedd to send Http Request in my Blackberry Application.Can any body help me what are the
packages that i have to import for Http request & how I have to send Http request of an url.
Thanks,
Raghuveer.
03-11-2011 08:22 AM
Try with this sample code.
import java.io.IOException; import java.io.InputStreamReader; import javax.microedition.io.HttpConnection; import net.rim.device.api.io.transport.ConnectionDescriptor; import net.rim.device.api.io.transport.ConnectionFactory; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.component.RichTextField; import net.rim.device.api.ui.container.MainScreen; public class HttpSample extends MainScreen { public HttpSample() { ConnectionFactory factory = new ConnectionFactory(); ConnectionDescriptor conDescriptor = factory.getConnection("http://www.blackberry.com"); HttpConnection conn = (HttpConnection) conDescriptor.getConnection(); StringBuffer raw = new StringBuffer(); try { if (conn.getResponseCode() == HttpConnection.HTTP_OK) { java.io.Reader r = new InputStreamReader(conn.openInputStream()); int ch; while ((ch = r.read()) != -1) { raw.append((char) ch); } add(new RichTextField(raw.toString(), Field.READONLY)); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
03-11-2011 11:17 PM
03-12-2011 02:05 AM
Thanks for solution....
But it works only in simulator where as gives error : "Some required files are missing" while loading in to the
device. At present I am using JDE 5.0.
03-12-2011 02:24 AM
03-12-2011 10:06 AM
Please check your device's operating system version, the classes 'net.rim.device.api.io.transport.ConnectionDescript
03-12-2011 10:28 AM
try with this other sample.
import java.io.IOException;
import java.io.InputStreamReader;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
public class HttpSampleScreen extends MainScreen {
public HttpSampleScreen() {
try {
HttpConnection conn = (HttpConnection) Connector.open("http://www.blackberry.com");
StringBuffer raw = new StringBuffer();
if (conn.getResponseCode() == HttpConnection.HTTP_OK) {
java.io.Reader r = new InputStreamReader(conn.openInputStream());
int ch;
while ((ch = r.read()) != -1) {
raw.append((char) ch);
}
add(new RichTextField(raw.toString(), Field.READONLY));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
03-15-2011 08:41 AM
Hi,
At present my device version is 4.6 and whie I got the exception "Tunnel failed". i dont know how it
works in version 4.6. While some body help in this situation..
Thanks,
Raghuveer.