1

I want to login to my Blackberryapp, but this app still in method GET, I want to change this app into method POST. Because my server using method POST. This is my source code in my BB app.

    package com.blackberry.mobile_banking;

import java.io.InputStream;
import java.io.InputStreamReader;

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

import net.rim.blackberry.api.browser.URLEncodedPostData;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;

public class Check_Login {

    HttpConnection httpconnection;
    InputStream inputstream;

    public Check_Login()
    {
    }
    public void validasi_Login(String username, String password)
    {
        try {
            URLEncodedPostData params=new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, true);
            params.append("username", username);
            params.append("password", password);
            String url="http://127.0.0.1:80/proyek_akhir/cek_login.php?"+params.toString()+";deviceside=true";
            System.out.println(url);

            //connect to server

            httpconnection=(HttpConnection)Connector.open(url);
            inputstream=httpconnection.openDataInputStream();

            if(httpconnection.getResponseCode()==HttpConnection.HTTP_OK)
            {
                InputStreamReader reader=new InputStreamReader(inputstream, "UTF-8");
                int readCharacter;
                StringBuffer responseBuffer=new StringBuffer();

                while((readCharacter=reader.read())!=-1)
                {
                    responseBuffer.append((char)readCharacter);

                }
                if(responseBuffer.toString().equalsIgnoreCase("SUCCESS"))
                {
                    Screen_Home sc_home=new Screen_Home();
                    UiApplication.getUiApplication().pushScreen(sc_home);
                }
                else if(responseBuffer.toString().equalsIgnoreCase("FAILED"))
                {
                    Dialog.alert("Username or Password wrong");

                }
            }

        } catch (Exception e) {

        }

    }

}

and this my source code in my server

  <?php
    require('db.php');
    $username=$_POST['username'];
    $password=md5($_POST['password']);
    $query="select*from user where username='$username' and password='$password'";
    $hasil=mysql_query($query);
    if(mysql_num_rows($hasil)>0)
    {
        echo "SUCCESS";
    }
    else
    {
        echo "FAILED";
    }
?>
  • possible duplicate of [Http POST in BlackBerry](http://stackoverflow.com/questions/6184223/http-post-in-blackberry). also, the same comment as on your last question ... you're performing network requests on the UI thread, which is a bad idea. – Nate Jul 05 '13 at 08:56
  • @Irwan Harianto L Try this one: http://stackoverflow.com/questions/8969666/http-post-blackberry-null-response/8981963#8981963 – alishaik786 Jul 06 '13 at 05:41

3 Answers3

1

Unless your app were a MIDlet, or a legacy pre-5.0 application, I'd use the newer ConnectionFactory class to avoid problems with the transport types (BES, BIS, Wi-Fi, etc). Back in the old days we had to append a different suffix for each transport type to the URL. You can avoid that creating a new factory, which you can configure once and reuse in other parts of the code:

        ConnectionFactory factory = new ConnectionFactory();
        factory.setPreferredTransportTypes(<array of TransportInfo.TRANSPORT_XXX >);
        factory.setTransportTypeOptions(<options>); //Only required for BIS
        ... 

Then each time you need a connection you obtain the HttpConnection object like this:

        ConnectionDescriptor cd = factory.getConnection(<url>);
        HttpConnection httpConn = (HttpConnection) cd.getConnection();
        httpConn.setRequestMethod(HttpConnection.POST);
        //Now proceed as normal

The request method as you can see is configured in each new HttpConnection instance and has nothing to do with the factory.

Mister Smith
  • 27,417
  • 21
  • 110
  • 193
0

try this -

httpconnection=(HttpConnection)Connector.open(url);
httpconnection.setRequestMethod(HttpConnection.POST);//this will use post method
Rince Thomas
  • 4,158
  • 5
  • 25
  • 44
0

I literally finished my POST method yesterday. This answer helped me a lot, you should be able to use it almost as is:

Blackberry jde : how to upload an image in server using MultipartPostData

Community
  • 1
  • 1
Kevin
  • 1,626
  • 16
  • 30