Http method Post is not working in the Simulator (SDK 7.0) and not in the device with BB 5.0

I am a novice in the development of BB.

I tried to implement a simple Http Post request, but when running it in the Simulator (SDK 7.0), he gave an IOException.

I've first implemented the Http Get request and was getting the same error but that was resolved by adding "; deviceSide = true'on demand.

But while making the Post request parameters(username and password) were supposed to be written to outputstream open after successfully HttpConnection. I get the answer I used to get when I send two parameters as null.

But the app even when built against JRE 5.0 crashes.

Hi simon, peter

I made changes to my connection as as well as u say it, but still no idea if I am wrong, if I do one.

Now without using any suffix his run on my device but same answer as it was a GET request.

A modified version of class ServerConnection (in post above)

package com.httppostdemo.classes;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

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.UiApplication;
import net.rim.device.api.ui.component.Dialog;

public class HttpPostConnection extends Thread {

    private String mUrl = null;
    private byte[] mParams = null;

    public HttpPostConnection(String iUrl, byte[] iParams) {
        mUrl = iUrl;
        mParams = iParams;
    }

    public void run() {
        super.run();
        ConnectionFactory connectionFactory = new ConnectionFactory();
        ConnectionDescriptor connDescriptor = (ConnectionDescriptor) connectionFactory
                .getConnection(mUrl);
        HttpConnection connection;
        OutputStream outStream;
        InputStream responseData;
        final ByteArrayOutputStream baos;
        int responseCode;
        int bytesRead;

        if (connDescriptor != null) {
            try {

                connection = (HttpConnection) connDescriptor.getConnection();
                connection.setRequestMethod(HttpConnection.POST);
                connection.setRequestProperty("Content-Type",
                        "application/xwww-form-urlencoded");
                connection.setRequestProperty("Content-Length",
                        String.valueOf(mParams.length));

                outStream = connection.openOutputStream();
                outStream.write(mParams);
                outStream.close();

                responseCode = connection.getResponseCode();
                if (responseCode != HttpConnection.HTTP_OK) {
                    connection.close();
                    return;
                }

                baos = new ByteArrayOutputStream();
                responseData = connection.openInputStream();
                byte[] buffer = new byte[10000];
                bytesRead = responseData.read(buffer);
                while (bytesRead > 0) {
                    baos.write(buffer, 0, bytesRead);
                    bytesRead = responseData.read(buffer);
                }
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        Dialog.alert(new String(baos.toByteArray()));
                    }
                });
                baos.close();
                connection.close();

            } catch (final Exception e) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        Dialog.alert("Exception :: " + e.getMessage());
                    }
                });
            }

        }
    }

}

Tags: BlackBerry Developers

Similar Questions

  • Make HttpConnection work on the device

    Hello

    I have a java program that uses a HttpConnection (in the main thread). It works quite well on the Simulator, but when I run it on my device (8310 Curve), she just do nothing! Even after asking to allow the application to make http connections.

    I hear some APN settings to configure on the device. I did it too ("airtelgprs.com" with name of user and password blank for Airtel, India).

    Is there something else that does not leave my request to make http connections? Can someone please tell me what all I should do tomake my http connections work on the device?

    Thank you

    -Arun

    This means that you can perform a blocking i/o operation, as an HTTP connection, thread in your event management program. You must create a worker thread to manage the operations of HTTP connection.

  • What is the controller of xbox to microsoft for the work of the PC with windows 8?

    What is the controller of xbox to microsoft for the work of the PC with windows 8?

    Hello

    Do you use a wired or wireless Xbox controller?

    Yes, you can connect Xbox controller to Windows 8. I suggest you return the item if you use wired Xbox Controller and check if it helps.

    Connect an Xbox 360 wired controller to your computer
    http://support.Xbox.com/en-us/Xbox-360/accessories/connect-wired-controller-computer

    If you use wireless, please refer to the article for more information.

    Set up your Xbox 360 for Windows controller
    http://support.Xbox.com/en-us/Games/PC-games/Xbox-controller-for-Windows-Setup

    Hope this information helps. Answer the post with an up-to-date issue report to help you further.

  • Amazon Cloud Player or Google Reader works on the Surface with Windows RT?

    Amazon Cloud Player or Google Reader works on the Surface with Windows RT?

    I think that the answer is no, and if yes, what are the types of applications/services that are likely to be developed for the Surface (Windows RT) Finally?
    In addition, these things (Amazon Cloud Player and Google Drive) will be available on the version of Windows 8 fantasy of the Surface when it comes out?
    A Surface of Windows, I bought for my mother and I did not open and I just check all these things. A laptop is perhaps better for her, but I have little that this is best for some reason any.
    Thank you.
     
    Original title: amazon cloud player

    The Surface Pro is a full PC and runs Windows 8, you can install the Amazon downloader and download the song files as you do now on a regular PC. Surface RT runs Windows RT and does not run as many different applications such as Surface Pro.

    You can play songs streamed from the web version of Amazon Cloud Player on Windows 8 and Windows RT. Currently, I'm not aware of any way to download songs from Amazon directly on Windows RT. You will first need to download them on a normal PC and then copy them to the Surface RT if you want to listen to the songs without a network connection.

    There is no Google Drive for Windows RT application so far, but Microsoft did something similar, called SkyDrive.

    In addition, just for the record it is a Kindle for Windows 8 and Windows RT application, so that you can read your Kindle eBooks.

    I speak from experience, having recently purchased a Surface RT to play with. I hope this helps.

  • Adobe Premiere Elements doesn't recognize my camcorder - Canon GL-2.  Can I make it work?  The device worked very well with my old computer (just died) and an older version of Premiere Pro. Any suggestions?

    Adobe Premiere Elements doesn't recognize my camcorder - Canon GL-2.  Can I make it work?  The device worked very well with my old computer (just died) and an older version of Premiere Pro. Any suggestions?

    Version 13 capture is more than one camera to tape

    http://helpx.Adobe.com/premiere-elements/KB/removed-features-formats-elements.html

  • How to restore the devices with removable storage "missing icons

    HelloW sir This is krivy! for some time more I'm months local disk G not displaying don't not its icon (devices with removable storage) totally absent I m so depressed about this because I m unable to put my pen-drive & usb Cables & having so much work to the system that has information in the key USB sir could you tell me a solution for this problem

    Hi krivy,.
     
    Method 1: Check if the drive is visible in disk management.
     
    a. right click on my computer > Manage > Disk Management > right click on the removable storage drive and select Change drive letter > select a new drive letter not already in use.
     
    See if that helps.
     

    Method 2: Run the troubleshooter from the link given below and if that helps.

    Hardware devices not detected or does not

  • WebWorks app does not work on the device

    I am currently working on the webworks app and then I compiled the app on Mac environtment. My application get not problem with the compilation of the process, but it does not start on a real device.

    My smart phone BlackBerry say: cannot display the file

    Thanks for the help

    @andriansandi

    Solved now

  • Notification do not work in the device

    Hello, I have "create a simple application to the notification of the test, but application not working on my device and display the error"error at startup PushNotification; Module 'PushNotification' trying to access a secure API. ».

    My code is:

    SerializableAttribute public class PushNotification extends UiApplication {}

    Public Shared Sub main (String [] args) {}

    PushNotification pn = new PushNotification();
    pn.enterEventDispatcher ();
    }

    {PushNotification()}
    pushScreen (new ScreenStart());
    }
    }

    class ScreenStart extends form {}

    {ScreenStart()}
    setTitle ("notice of application");

    ButtonField bf = new ButtonField ("receipt Notification");
    bf.setChangeListener (new FieldChangeListener() {}

    ' Public Sub fieldChanged (field field, int context) {}
    try {}
    ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance ();
    EncodedImage image = EncodedImage.getEncodedImageResource ("icon.png");
    ApplicationIcon icon = new ApplicationIcon (image);
    Indicator of ApplicationIndicator = reg.register (true false, icon);
    indicator.setValue (7);
    }
    catch (Exception e) {}

    }

    }
    });
    Add (BF);

    ButtonField CFB = new ButtonField ("own Notification");
    bfc.setChangeListener (new FieldChangeListener() {}

    ' Public Sub fieldChanged (field field, int context) {}
    try {}
    ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance ();
    Reg.Unregister ();
    }
    catch (Exception e) {}
    }
    }
    });
    Add (CFB);

    }
    }

    CUMPS

    Have you signed the application before putting it on the device?

  • Why Apple ID work for the devices iOS and Yosemite... .but not for iCloud?

    Recently, I upgraded to Yosemite. So I was forced to change my PWD for Apple ID.  I have AN AppleID account. After having changed the PWD, other requested change upgrade iOS devices, and all the work.

    UNLESS iCloud refuses to accept my new Apple ID... All other devices, updates work fine with the new PWD AppleID...

    What is the problem with iCloud?

    How can I force it to accept the Apple that accept all other devices/systems ID?

    Jim B

    Have you tried the signature to iCloud and then again?

    What to do after changing Apple ID or password - email address

  • Suddenly, my sound card does not work - try the devices and add/install the old hardware on the Assistant Manager, he finds ADSInstant HTV PC1, but sending the message... Impossible to install correctly the code 10

    tried the Device Manager and add/install the old hardware on the wizard... he finds ADSInstant HTV PC1, but sending the message... Impossible to install correctly the code 10

    Restore the system to then it was working properly.

  • Video recording of blackBerry Smartphones does not work (on the device itself)

    When you try to save a videa, I get the message "to save a videa, insert a memory card.  I have indeed NO card inserted, but in my previous blackberry, I might save it on the device itself.  I already tried to solve via disable the card Support (via options > device > storage > Media Card Support) but to no avail.   Can someone help me?

    Thank you

    Hi @PatDenis! Welcome to the community of BlackBerry Support Forums!

    Unfortunately, you have need of more memory to perform this task, you need a memory card to be able to start recording a video.  Moreover, the 9720 isn't a "BOLD" (according to your profile), it is fair to BlackBerry 9720. See you soon!

    Record a video

  • Why is it not possible to use SIRI on my apple TV remote to control the HomeKit products? I should be able to control all the devices with my Apple TV remote and SIRI HomeKit!

    Why is it not possible to use SIRI on my apple TV remote to control the HomeKit products? I should be able to control all the devices of HomeKit with my SIRI voice remote control and using Apple TV!

    If the new apple TV can act as a concentrator HomeKit and I use SIRI on my iPhone to control my locks, thermostat, lights, etc. Why am I not able to do the same thing with SIRI via voice commands on my Apple TV remote? When is this going to work?

    Also, when Apple will come out with a response to the echo of Amazon? I've tired to wait... do it already! If you build it, they will come...

    Thank you!

    This is a community to a user, and Apple will not see your rant. If you have suggestions about Apple TV, Siri and HomeKit the best thing to do is to submit your comments here. http://www.Apple.com/feedback/AppleTV.html

  • Safely remove the device with VISTA is not infallible

    I have a HP Pavilion Slimline nine running Vista.

    I plug a USB key or an external hard drive and it reads very well.

    I have try the safely eject button, and the light on my memory stick stays on. With XP, it came out, and I knew that I could remove the stick. It goes the same for my external hard drive... Done, I could hear that he stop and watch out slight shift when I used the feature of MATERIAL in any SAFETY REMOVE (SRH) of XP.

    Not the case with VISTA. After completing the SRH steps, these devices always seem to be on.

    I read that Vista not turn off light after things are ejected... is - it true?
    Any suggestions?

    Are there any patches or downloadable patches?

    Hello walden1,

    Thanks for posting on the Microsoft answers Community Forum.

    The only time where SRH did not finish is when there is an application or a service that is always access the drive somehow.  I fyou're sure there is no transfer, then you can disconnect with the safety of the food.  themajin concern is when access to the data or transfer is underway.

    -J' read that Vista not turn off light after things are ejected... is - it true?
    It has been my experience that it's false.  Once ejected, using SRH or not the light turns off and the player is uninstalled.  Now, if you use memory for ready boost of course light remains lit and SRH still not eject it.  So maybe it's somehting that you'll want to check.  If your right click the drive in the Solution Explorer, then select properties the last tab should be the tab ready boost and you can switch if and how much of the training will be used for this.

    Thank you
    Jonathan

  • When my program works in the Win7 with aero theme, the border of the video continues to blink.

    My program is used to read a video written by the DirectShow.  However, when using the aero theme. the border of the video keeps flashing. other themes doesn't have this bug.

    Hello

    According to the description of the problem, I can understand when you use the aero theme, the boarder continues blinking while a video is playing. Don't worry, we'll guide you to get the problem resolved.

    Please answer the following questions in order to better understand the issue.

    1. Are you facing this problem on all the videos that you are trying to play?

    Method 1

    Run Troubleshooter of aero theme

    http://Windows.Microsoft.com/en-us/Windows7/open-the-Aero-Troubleshooter

    If the problem persists, follow method 2.

    Method 2

    You can run the below mentioned fixit to correct the problem with the effects of glass.

    http://Support2.Microsoft.com/mats/aero_effects_not_working/en-us

    If the problem persists, follow method 3

    Method 3

    I suggest you to update the graphics drivers and check if the problem persists.

    http://Windows.Microsoft.com/en-us/Windows/Update-driver-hardware-ISN

    I hope this helps. Write to us for assistance.

  • Transfer works if the device is locked

    Hey just wondering does transfer if the devices are locked as I note when you use my iPhone the small icon is displayed only when my iPad is not locked and used but when my iPad is blocked I can't access the small icon on my phone and even on my iPhone iPad

    The device must be in use, according to transfer Bluetooth is active.

Maybe you are looking for

  • Detection of overruns of vibratory limit with FFT

    Hi all We follow a piece of rotating machinery for vibratory limit overruns.  Our acquisition of digital data is running at 3333Hz with anti-aliasing in front of the ADC analog filters.  We sample at least 5 times on the highest frequency of interest

  • the power of the spectrum graph and butterworth filter

    Hello I am beginner in labview, I want to see the power spectrum of the sound samples, I want to see if there is any reason in these samples. I use spectral measure, and then I filtered with butterworth filter samples. For output I using waveform gra

  • compatible with development?

    is compatible with toshiba microsoft Office prosper (android OS)?

  • Is it so difficult to plug a new sata drive into XPS8500?

    Hello world My Bios Setup: Start-up: RAID / UEFI SATA 0: 2 TB seagate (Windows 8) SATA 5: Xxxx PLDS DVD SATA 2: 1For seagate one I want to install SATA 3: no mSata 1: Samsung SSD 32 MB (Windows 8) I tried many things but nothing works. The only thing

  • BlackBerry Smartphones upgrade necessary?

    I just got a blackberry 9360 today and my phone says my software is up to date but when I plugged in my laptop to transfer data, it is said there is an update available the current package I have is 1680