Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry® World™ Development

Reply
New Contributor
raghuveer_shn
Posts: 9
Registered: ‎02-08-2011
My Device: 8520

Http Request in Blackberry

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.

 

New Contributor
jeysterg
Posts: 5
Registered: ‎03-08-2011
My Device: Blackberry Curve 8530

Re: Http Request in Blackberry

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();
		}
	}
}

 

 

New Contributor
raghuveer_shn
Posts: 9
Registered: ‎02-08-2011
My Device: 8520

Re: Http Request in Blackberry

Thanks u very much.....It works...
New Contributor
raghuveer_shn
Posts: 9
Registered: ‎02-08-2011
My Device: 8520

Re: Http Request in Blackberry

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.

New Member
akash01
Posts: 1
Registered: ‎03-12-2011
My Device: Black berry Curve-9300

How to register Complain for Service center

Hi all... I own a Curve9300 model handset. I had a very bad experience with the handset and also with the customer service center in New Delhi,Vikasmarg(where I'm located) and more than 15 days was passed but they are not able to tell when will be my set get repaired. I have called so many times on local customer care number and even wrote mails to them but no action has been taken and my mails went un answered. I had been looking for an email id to send my complaints about the customer care center, but couldnt find any in the BB web site... Requsting to all if anyone can provided an email id, where I can escalate my issues? Thanks in advance..
New Contributor
jeysterg
Posts: 5
Registered: ‎03-08-2011
My Device: Blackberry Curve 8530

Re: Http Request in Blackberry

Please check your device's operating system version, the classes 'net.rim.device.api.io.transport.ConnectionDescriptor' and 'net.rim.device.api.io.transport.ConnectionFactory' are supported since Blackberry API 5.

New Contributor
jeysterg
Posts: 5
Registered: ‎03-08-2011
My Device: Blackberry Curve 8530

Re: Http Request in Blackberry

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();
		}
	}
}

 

 

New Contributor
raghuveer_shn
Posts: 9
Registered: ‎02-08-2011
My Device: 8520

Re: Http Request in Blackberry

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.