Search code examples
javablackberryblackberry-simulatorblackberry-eclipse-pluginblackberry-jde

Http POST in BlackBerry


Greetings,

I am trying to setup a server connection from my BlackBerry Application . I was able to get a response code on the status of the server. Now i have a few values which i have to POST to the server

Its like a registration page values(username, password, age ) have to be sent to the server .

        ConnectionFactory connFact = new ConnectionFactory();
        ConnectionDescriptor connDesc;
        connDesc = connFact.getConnection(url);
        if (connDesc != null)
        {
            HttpConnection httpConn;
            httpConn = (HttpConnection)connDesc.getConnection();
            try
            {
                final int iResponseCode = httpConn.getResponseCode();
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        Dialog.alert("Response code: " + Integer.toString(iResponseCode));
                    }
                });
            }
            catch (IOException e)
            {
                System.err.println("Caught IOException: " + e.getMessage());
            }
        }

Thats the code i used to get the response code. I would appreciate it if someone could help me how i can make a POST request to the server.. the server url for status was company.com/app/version/stats

when it for register it would be company.com/app/register

Thank you


Solution

  •  ...
    httpConn = (HttpConnection)connDesc.getConnection();    
    httpConn.setRequestMethod(HttpConnection.POST);
    httpConn.setRequestProperty("username",name);
    httpConn.setRequestProperty("password",pass);
    ....