Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

how to pass the parameter through http

hi experts,

                 as i have createrd a login page using blackberry API's....

now i need to pass username and password to server via HTTP....... can anybody tell me how to send the 

parameter.......... 

Highlighted
Developer
Posts: 374
Registered: ‎04-07-2010
My Device: Bold 9000
My Carrier: Airtel

Re: how to pass the parameter through http

Use Url Encoded POST Request.

check this link:


http://supportforums.blackberry.com/t5/Java-Development/question-about-sending-by-post-and-using-Url...

Press the Like button (Thumb up) on the left side to thank and
please mark the Thread as solved if its solved...
K.S
Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: how to pass the parameter through http

Hi,

   check  this

public boolean OpenSocketConnection() {
        SocketConnection proxy_connection = null;
        OutputStream output_stream = null;
        InputStream input_stream = null;

        
        try {
                    
            if ( !UpdateConnectionSuffix() ) {  //this is the connection suffix-- for wifi with proxy and wifi connection url should be appended with ";interface=wifi"
                return false;
            }
            
            // Encode the login information in Base64 format.
            String login = WIFI_PROXY_USER + ":" +WIFI_PROXY_PASSWORD;
            byte[] encoded_login = Base64OutputStream.encode(login.getBytes(), 0, login.length(), false, false);
            
            proxy_connection = (SocketConnection)Connector.open( "socket://" + WIFI_PROXY_SERVER + ":" + WIFI_PROXY_PORT + _connectionSuffix );
            StringBuffer buf = new StringBuffer();
            
            buf.append( "GET " + _url + " HTTP/1.1\n" );
            if(jadHost != null){
                buf.append( "Host: " + jadHost + "\n" );
            }else{
                buf.append( "Host: " + URL + "\n" );
            }
            buf.append( "Proxy-Authorization: Basic " + new String(encoded_login) + "\n" );
            buf.append( "Content-Language: en-US\n" );
            buf.append( "Connection: close\n" );
            buf.append( "User-Agent: Profile/MIDP-2.0 Configuration/CLDC-1.0\n" );
            buf.append( "\n" );
            
            output_stream = proxy_connection.openOutputStream();  
            input_stream = proxy_connection.openInputStream();
            output_stream.write( buf.toString().getBytes() );
            output_stream.flush();

            byte[] data = new byte[2048];
            int len = 0;
            int size = 0;
            StringBuffer raw = new StringBuffer();
            
            while ( -1 != (len = input_stream.read(data)) ) {
                raw.append(new String(data, 0, len));
                size += len;
            }
            
            String full_response = raw.toString();
            String response_header = full_response.substring(0, full_response.indexOf("\r\n\r\n")).trim();
            
            if ( response_header.toUpperCase().indexOf("HTTP/1.1 200 OK") != -1 ) {
                blnConnected = true;
                responseMessage = full_response.substring(full_response.indexOf("\r\n\r\n")).trim();
            } else {
                blnConnected = false;
                responseMessage = "Unable to establish server connection.";
            }
        } catch (IOException ioe) {
            blnConnected = false;
            responseMessage = "Unable to establish server connection.";
            //responseMessage += "\n\nHTTPHandler - OpenSocketConnection - Error: " + ioe.toString();
            
            System.err.println("HTTPHandler - OpenSocketConnection : " + ioe.toString() + "\n" + _url);
            ioe.printStackTrace();
        } catch (Exception e) {
            blnConnected = false;
            responseMessage = "Unable to establish server connection.";
            //responseMessage += "\n\nHTTPHandler - OpenSocketConnection - Error: " + e.toString();
            
            System.err.println("HTTPHandler - OpenSocketConnection : " + e.toString() + "\n" + _url);
            e.printStackTrace();
        } finally {
            try {
                if ( input_stream != null ) {
                    input_stream.close();
                }
                if ( output_stream != null ) {
                    output_stream.close();
                }
                if ( proxy_connection != null ) {
                    proxy_connection.close();
                }
            } catch (Exception e) {
            }
            
            input_stream = null;
            output_stream = null;
            proxy_connection = null;
        }
        
        return blnConnected;
    }

 Thanks & Regards

               pp

Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: how to pass the parameter through http

 

hello,

 

 

i am using mds connection, do i need socket connection... ... i will send my code....

here conncection is established to my server . but i want to send idField and pwdField to server URL........... how to send it. Is socket connection is needed?.... server side programming is already done....... just i need to send these

string values to server url....... i didnt write to code to send string value.. only conncetion is established in my code...if of BB experts know how to send string value to url.. plz add code to it...

 

 

String idField=bef.getText();

String pwdField=pwd.getText();

 

try{

//URLEncodedPostData _urlEncoded =new URLEncodedPostData(null, false);

//_urlEncoded.append("frame", ""+idField);

 

//where _firstFrame is byte[] array

String url ="http://192.168.0.67/acusismg";

HttpConnection httpConn = (HttpConnection)Connector.open(url,Connector.READ_WRITE);

httpConn.setRequestMethod(HttpConnection.POST);

 

// conn.setRequestMethod(HttpConnection.POST);//httpConn.setRequestProperty("name","abc");

// httpConn.setRequestProperty("Address","xyz");// Getting the output stream may flush the headers

//OutputStream os = httpConn.openOutputStream();

//os.write("Information \n".getBytes());

//Dialog.alert(os.toString());

//os.flush();

if (httpConn.getResponseCode()==HttpConnection.HTTP_OK)

{

add(

new LabelField("success to post"+httpConn.getResponseMessage()));

}

else add(new LabelField("error to post"));

 

}

catch(IOException e) {

 

// TODO Auto-generated catch block

Dialog.alert(e.toString());

}

//Subchunk1IDcatch(Exception e) {

 

// TODO Auto-generated catch block

Dialog.alert(e.toString());

}

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to pass the parameter through http

"server side programming is already done"

 

The requirements of the Server code will determine how you do this.  Ask your server code developer what s/he wants.

Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: how to pass the parameter through http

ya, u where right... after consulting server side programer.... he gave me server URL(http://*****/*****mg/User/Login).

then he told to pass value to this............ as username and passward.......... 

  but the code above do the same... but for every value of username and password i send i am getting same output..... may be its not checking the value.......plz help

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to pass the parameter through http

[ Edited ]

Seems to me it would be better to ask your Server processing person what you are doing wrong and not us.  We don't know what is expected and they do.  And they can probably trace what you send to to understand what you are doing wrong too. 

Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: how to pass the parameter through http

thanku petter....