Http connection error on the blackberry real device

限于喜欢 提交于 2019-12-02 03:10:26

If it is enough that your program works with OS 5.0+, then try using Network API:

ConnectionFactory f = new ConnectionFactory();
ConnectionDescriptor descr = f.getConnection("http://www.google.com");

HttpConnection connection = (HttpConnection) descr.getConnection();

That piece of code tries to use the first available connection type. You can fine tune it if you want.

Regarding debugging, just install BlackBerry Desktop Software, connect your 8520 with the USB cable and from eclipse, click Run -> Debug As... -> BlackBerry Device.

Terrick Mansur

The connection factory worked perfectly on the new devices, but didn't work with some of the older ones like the curve and bold. This is what solved it for me:

BrowserField browserField = new BrowserField();
BrowserFieldRequest Req = new BrowserFieldRequest("http://www.yourserver.com/");

InputStream inputStream = browserField.getConnectionManager().makeRequest(Req).openInputStream();

Try to redirect the link using following code:

 HttpConnection hc = (HttpConnection) Connector.open(url1);

 hc.setRequestMethod(HttpConnection.GET);
 hc.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
 InputStream is = null;
 String location =hc.getHeaderField("Location");

 HttpConnection hcc = (HttpConnection) Connector.open(location);
 is = hcc.openDataInputStream();

Try to add transport to address For example for connect via wi-fi :

httpConnection = (HttpConnection)Connector.open("http://www.google.com;interface=wifi"); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!