Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6983507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:25:40+00:00 2026-05-27T18:25:40+00:00

/* Hi Iam developing an application where the BB app needs to post data

  • 0

/* Hi Iam developing an application where the BB app needs to post data to server. The Http connection works fine on Blackberry emulator, but when i try to test it on a real device the application cannot post data to server. the following is my code:
*/

package com.sims.datahandler;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;

import com.sims.commonmethods.CommonMethods;
import com.sims.screens.MenuScreen;

/**
 * 
 * @author SaiKrishnaPawar
 *
 */
public class GPRSHandler extends Thread {

        private String data;
        private String url;
        private String msgKey;
        private String mobileNumber;

        public String sendGPRSRequest() {

             HttpConnection httpConn = null;
             DataOutputStream oStrm = null;
             DataInputStream is = null;

             byte[] resp = null;
             String responseData;
             try {

                 // Creating httpconnection object to handle GPRS request
                 httpConn = (HttpConnection) Connector.open(url);

                 httpConn.setRequestMethod(HttpConnection.POST);
                 httpConn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0");
                 httpConn.setRequestProperty("Accept_Language", "en-US");
                 httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

                 oStrm = httpConn.openDataOutputStream();

                 byte dataArray[] = (mobileNumber + "&" + msgKey + data).getBytes();

//               byte dataArray[] = (msgKey + data).getBytes();

                 CommonMethods.getSystemOutput("msg key and data:::"+mobileNumber + msgKey + data);

                 for (int i = 0; i < dataArray.length; i++) {
                     oStrm.writeByte(dataArray[i]);
                 }
                 DataInputStream din = httpConn.openDataInputStream();
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 int ch;
                 while ((ch = din.read()) != -1) {
                     baos.write(ch);
                 }

                 resp = baos.toByteArray();
                 responseData = new String(resp);
                 baos.close();
                 din.close();
                 httpConn.close();

                 return responseData.trim();

             } catch (IOException ex) {

                 CommonMethods.getSystemOutput("IO Exception in run method of gprs handler::" + ex.getMessage());

                 UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {

                    int choice = Dialog.ask(Dialog.D_OK, "No Connectivity");

                    exitApp(choice);

                    }
                });

             } catch (NullPointerException nex) {

                 CommonMethods.getSystemOutput("NullPointerException:" + nex.getMessage());

             } catch (SecurityException e) {

                 CommonMethods.getSystemOutput("SecurityException:" + e.getMessage());

                 UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {

                        Dialog.ask(Dialog.OK, "Security Exception");

                        UiApplication.getUiApplication().pushScreen(new MenuScreen());

                    }
                });

             } finally {
                 try {
                     if (is != null) {
                         is.close();
                     }
                     if (oStrm != null) {
                         oStrm.close();
                     }
                     if (httpConn != null) {
                         httpConn.close();
                     }

                 } catch (Exception ex) {

                     UiApplication.getUiApplication().invokeLater(new Runnable() {

                        public void run() {

                            Dialog.ask(Dialog.OK, "ERROR in While Connecting GPRS Connection");

                            UiApplication.getUiApplication().pushScreen(new MenuScreen());

                        }
                    });
                 }
             }

             return null;
        }

        public void setData(String data) {
            this.data = data;
        }

        public void setMsgKey(String msgKey) {
            this.msgKey = msgKey;
        }

        public void setUrl(String url) {
            this.url = url + ";deviceside=false";
        }

        public void setMobileNumber(String mobileNumber) {

            this.mobileNumber = mobileNumber;

        }

        private void exitApp(int choice) {

            System.exit(0);

        }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:25:41+00:00Added an answer on May 27, 2026 at 6:25 pm
       httpConn = (HttpConnection) Connector.open(url);
    

    instead of this you can write//

       url = url + ";deviceside=false";
       httpConn = (HttpConnection) Connector.open(url);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a Java Desktop Application . This app needs a configuration to
I am developing an application in cocoa,which needs to check whether that app is
I am developing JavaME LWUIT application which needs to display some data on map.
I'm developing a Adobe AIR application using Flash Builder 4. This app needs to
I am developing a C# .NET application. In the app.config file I add trace
I am developing an application to install a large number of data files from
I am developing an application that needs to use regini (because of legacy reasons)
I am developing an Android app that needs to receive specific informations for each
I am developing an application using Eclipselink and as part of the app I
I am developing a web app but is not satisfied with is architecture that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.