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

  • SEARCH
  • Home
  • 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 7515119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:42:07+00:00 2026-05-30T00:42:07+00:00

how can i send JSON request from blackberry application that works as client to

  • 0

how can i send JSON request from blackberry application that works as client to the server to get an information from the server to use them in BB application
i use blackberry eclipse under windows 7

i try this code

public void loginRequest() throws IOException, JSONException{
    HttpConnection c = null;
    InputStream is = null;
    int rc;

    JSONObject postObject = new JSONObject();
    postObject.put("method", method);
    //postObject.put("params", Parameters);

    try{
        c = (HttpConnection)Connector.open(urlPath);

        // Set the request method and headers
        c.setRequestMethod(HttpConnection.GET);
        c.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
        c.setRequestProperty("Content-Length", "" + (postObject.toString().length() - 2));
        c.setRequestProperty("method", "GET");

        // Getting the response code will open the connection,
        // send the request, and read the HTTP response headers.
        // The headers are stored until requested.
        rc = c.getResponseCode();
        if (rc != HttpConnection.HTTP_OK){
            throw new IOException("HTTP response code: " + rc);
        }

        is = c.openInputStream();

        // Get the length and process the data
        int len = (int)c.getLength();
        if (len > 0){
             int actual = 0;
             int bytesread = 0 ;
             byte[] data = new byte[len];
             while ((bytesread != len) && (actual != -1)){
                actual = is.read(data, bytesread, len - bytesread);
                bytesread += actual;
             }
             //Get the JSON String
            System.out.println(new String(data));
        }
        else{
            int ch;
            while ((ch = is.read()) != -1){
                //TODO
                /*
                process((byte)ch);
                */
            }
        }
    }catch (ClassCastException e){
        throw new IllegalArgumentException("Not an HTTP URL");
    }finally {
        if (is != null)
            is.close();
        if (c != null)
            c.close();
    }
   }

i call this method by run method in a thread

when the simulator reach (rc = c.getResponseCode();) running code stops

i debug the code and it stops when it reach this statement with this error

Local connection timed out after ~ 120000

any help

  • 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-30T00:42:09+00:00Added an answer on May 30, 2026 at 12:42 am

    When running the application in simulator, make sure you enabled the Launch Mobile Data System Connection Service (MDS-CS) with simulator in Eclipse’s “Run Configurations” or “Debug Configurations”->”Simulator tab”->”General tab”.

    If it is not enabled, you should check this guide “Testing a BlackBerry device application with the BlackBerry Smartphone Simulator“, particularly the “Testing a BlackBerry device application that uses an HTTP connection” section. To make a long story short, you have to enable the MDS-CS. After enabling it, you should restart your simulator. Here is a quote from this guide:

    Start the BlackBerry MDS Connection Service when you start the BlackBerry Smartphone Simulator

    1. In Eclipse®, on the Run menu, click Debug Configurations or Run Configurations.
    2. Expand the BlackBerry Simulator item.
    3. Complete one of the following tasks:
      • To work with an existing launch configuration, under BlackBerry Simulator, click a launch configuration.
      • To create a new launch configuration, right-click BlackBerry Simulator, select New.
    4. Click the Simulator tab.
    5. Click the General tab.
    6. Select the Launch Mobile Data System Connection Service (MDS-CS) with simulator check box.
    7. Click Apply.

    Edit:
    Alternatively, when using a simulator you can add ;deviceside=true suffix to the url that you pass to Connector.open(). By setting deviceside=true you specify that the underlying TCP connection should be opened directly from the handheld (simulator in your case), therefore BlackBerry MDS Connection Service will not be used. Here is a code snippet based on your code:

    if (DeviceInfo.isSimulator()) {
        urlPath += ";deviceside=true";
    } else {
        urlPath += connectionDependentSuffix; // suffix that is relevant to
                                              // the desired connection option
    }
    c = (HttpConnection)Connector.open(urlPath);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use a GET request to send JSON to my server via
I need to make a nodejs client application that can send a POST request
I'm trying to send json string in the get request to the server, here
In HTML, you can send data from one page to another using a GET
How can I get Fullcalendar to cache events from a JSON feed? I don't
I'm trying to send a JSON string, from an Android 2.3 application, using Java
I have Spring REST application that can marshall an object to JSON when a
I can send any windows application key strokes with PostMessage api. But I can't
If webserver can send gzip response, why can't browser sent gzip request?
In Javascript I can send XML string to JSP server (XmlAction.jsp): Javascript Code: var

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.