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

Java Development

Reply
New Contributor
Posts: 3
Registered: ‎02-03-2012
My Device: All
My Carrier: All

HttpRequest not sent

Hello guys,

 

I'm developing a BB app which needs to call a webapp to retrieve some datas but I'm fairly new in java development for BlackBerry and i have a little problem with the httprequest.

When a request is sent to my webapp, i should see this request but i don't receive anything actually...

 

Here my code:

try
		{
			HttpConnection stream = (HttpConnection)Connector.open(url+";deviceside=true;interface=wifi",Connector.READ_WRITE, true);
			stream.setRequestMethod(HttpConnection.POST);
			URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
			encPostData.append("email", "fanorazafi@******");
			encPostData.append("password", "******");
			encPostData.append("source","blackberry");
			byte[] postData = encPostData.toString().getBytes("UTF-8");
			add(new RichTextField(encPostData.toString()));
			stream.setRequestProperty("Content-Length", String.valueOf(postData.length));
			OutputStream os = stream.openOutputStream();
			os.write(postData);
			os.flush();
			int rc = stream.getResponseCode();
			add(new RichTextField(Integer.toString(rc)));
			InputStream is = stream.openInputStream();
			byte[] data = new byte[256];
			int len = 0;
			StringBuffer raw = new StringBuffer();
			while ((len = is.read(data)) != -1 ) {
				raw.append(new String(data, 0, len));
			}
			String text = raw.toString();
			add(new RichTextField(text));
			is.close();
			stream.close();
		}
		catch(ClassCastException e)
		{
			throw new IllegalArgumentException("Not an HTTP URL");
		}

 Can somebody help me please?

 

Thanks

 

Contributor
Posts: 12
Registered: ‎08-16-2011
My Device: 9300
My Carrier: Telcel

Re: HttpRequest not sent

Have you tried to activate the "launch mobile data system connection service mds-cs" into your simulator configuration ? is a common source for that problem.
New Contributor
Posts: 3
Registered: ‎02-03-2012
My Device: All
My Carrier: All

Re: HttpRequest not sent

Hi urodba, thank you for your response.

So, i did not do that indeed... Where can I activate this module ?

Contributor
Posts: 12
Registered: ‎08-16-2011
My Device: 9300
My Carrier: Telcel

Re: HttpRequest not sent

That option is inside into your project properties, then you have to look for the run/debug option and choose the simulator you are using, then you have to look for simulator that is next to JRE, then in general configs there is a checkbox that activate this option
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: HttpRequest not sent

"deviceside=true" does no require the MDS-CS.

 

However, you also have "wifi" in your parameters - was this intentional? I think these might be mutually exclusive.

 

If you are testng on the simulator, start MDS-CS and remove these parameters from your connection string.

 

For device testing, you should be detecting the type of network and requestuing the appropriate connection type.

 

 

 

 

Highlighted
Contributor
Posts: 12
Registered: ‎08-16-2011
My Device: 9300
My Carrier: Telcel

Re: HttpRequest not sent

Yeah you're right, also i think that if you are using wifi you need to connect to the simulated wifi network (inside simulator like using a real device).
Developer
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL

Re: HttpRequest not sent

[ Edited ]

change your 

 

url+";deviceside=true;interface=wifi"

 

to this

 

public static String getConnectionString()
    {
	String con = "";
	if(DeviceInfo.isSimulator() == true)
	{
		return con;
	}
	if(WLANInfo.getWLANState() == 4620)
	{
		// for WIFI
		con = ";interface=wifi"; 
	}
	else if((CoverageInfo.getCoverageStatus() & 2) == 2)
	{
		// for BES
		con = ";deviceside=false";			
	}
	else if(getBIBSRecord() == null)
	{
		// for Direct TCP
		con = ";deviceside=true";
	}
	else{
		// for BISB
		con = ";deviceside=false;ConnectionType=mdss-ppublic";
	}
	con += ";ConnectionTimeout=120000";
	return con;
    }	
	
public static ServiceRecord getBIBSRecord()
{		
	ServiceRecord[] serviceRecord = ServiceBook.getSB().getRecords();
	int count = 0;
	while(istore1 < serviceRecord.length)
	{
		if(serviceRecord[count].getCid().equals("IPPP"))
		{
			count++;				
		}
		else if(serviceRecord[count].getName().indexOf("BIBS") > 0)
		{
			return serviceRecord[count];
		}
		else if(serviceRecord[count].getName().indexOf("5 Click") < 0)
		{
			return serviceRecord[count];
		}
	}
	return null;
}

 

 

 url + getConnectionString();

Regular Contributor
Posts: 59
Registered: ‎06-10-2011
My Device: 4.7
My Carrier: BB

Re: HttpRequest not sent

  • Hii,

 

    Can you use the Url as Url=Url+getConnectionPerameter();

 

 

 

public static String getConnectionPerameter() {
String connectionParameters = "";
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
connectionParameters = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
connectionParameters = ";deviceside=true";
}
}
return connectionParameters;
}

New Contributor
Posts: 3
Registered: ‎02-03-2012
My Device: All
My Carrier: All

Re: HttpRequest not sent

Hi,

 

Thank you all for your responses, I will try all you said today, I had no time before.