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
Contributor
Posts: 22
Registered: ‎05-04-2012
My Device: BlackBerry Torch 9800
My Carrier: MTN Nigeria

Re: post data to php via http

@pakanjce12; ys i left out 'SociaLink' accidentally but even with the correct link, still didn't work
However using GET as simon suggested works perfectly... Kudos Simon
Thank you both for helping me to figure it out
Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: post data to php via http

HI

 

Can you give me correct link please.

 

Thanks

Contributor
Posts: 22
Registered: ‎05-04-2012
My Device: BlackBerry Torch 9800
My Carrier: MTN Nigeria

Re: post data to php via http

Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: post data to php via http

Hi

 

This is code is working fine at my end. please test at your end.

 

package com.help;

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

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

import com.Novartis.utility.ConnectionInfo;
import com.Novartis.utility.Utility;

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

public class Help {
	public static boolean useraccount(String username,String password)
    {
	    boolean ret = false;
        InputStream inputStream = null;
        HttpConnection httpConnection = null;
        try
        {
            StringBuffer returnStringBuffer = new StringBuffer();
            String returnString = new String();
            String desiredEncoding = "ISO-8859-1";
            URLEncodedPostData params = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, true);
            params.append("username", "daniel");
            params.append("password", "daniel");
            String url = "http://www.onadabayi.x10.mx/SociaLink/test.php?"+params.toString()+ConnectionInfo.getInstance().getConnectionParameters();

httpConnection = (HttpConnection)Connector.open(url); inputStream = httpConnection.openDataInputStream(); if(httpConnection.getResponseCode() == HttpConnection.HTTP_OK) { int ch; String contenttype = httpConnection.getHeaderField("Content-Type"); if (contenttype != null) { contenttype = contenttype.toUpperCase(); if (contenttype.indexOf("UTF-8") != -1) { desiredEncoding = "UTF-8"; } } // get an inputstreamreader to handle utf-8 data InputStreamReader isr = new InputStreamReader(inputStream,desiredEncoding); while ((ch = isr.read()) != -1) { returnStringBuffer.append((char) ch); } inputStream.close(); httpConnection.close(); inputStream = null; httpConnection = null; returnString = returnStringBuffer.toString(); // examine return string if (returnString.indexOf("Success") != -1) { ret = true; } return ret; } inputStream.close(); httpConnection.close(); inputStream = null; httpConnection = null; //Bad Transaction. return ret; } catch (Exception e) { System.out.println("Error occurred in ProcessTransaction(,)\n" + e.toString()); return ret; } finally { try { if (inputStream != null) inputStream.close(); if (httpConnection != null) httpConnection.close(); } catch (Exception ee) { } } } }

 

Thanks

Pawan

Contributor
Posts: 22
Registered: ‎05-04-2012
My Device: BlackBerry Torch 9800
My Carrier: MTN Nigeria

Re: post data to php via http

This code works with the GET method and not with POST. The php file has been modified to use get that's why your getting a positive result.
Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: post data to php via http

Okay,

Henceforth you may try yourself.

Thanks