Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:58:56+00:00 2026-06-09T10:58:56+00:00

I am developing one application in which i need to pass parameter through POST

  • 0

I am developing one application in which i need to pass parameter through POST method so i have try to implement with HTTPConnection but it getting me error. the are no establish connection.in this code i have pass parameter with URLEncodedPostData but it cant

here is my code ::

URLEncodedPostData postData = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);
                    //passing q’s value and ie’s value
                    postData.append("q", "remoQte");
                    postData.append("ie", "UTF-8");

                    ConnectionFactory conFactory = new ConnectionFactory();
                    ConnectionDescriptor conDesc = null;
                    try{
                        conDesc = conFactory.getConnection("http://www.google.co.in/search");
                    }catch(Exception e){
                        System.out.println(e.toString()+":"+e.getMessage());
                    }
                    String response = ""; // this variable used for the server response
                    // if we can get the connection descriptor from ConnectionFactory
                    if(null != conDesc){
                        try{
                            HttpConnection connection = (HttpConnection)conDesc.getConnection();
                            //set the header property
                            connection.setRequestMethod(HttpConnection.POST);
                            connection.setRequestProperty("Content-Length", Integer.toString(postData.size())); //body content of post data
                            connection.setRequestProperty("Connection", "close"); // close the connection after success sending request and receiving response from the server
                            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // we set the content of this request as application/x-www-form-urlencoded, because the post data is encoded as form-urlencoded(if you print the post data string, it will be like this -> q=remoQte&ie=UTF-8).

                            //now it is time to write the post data into OutputStream
                            OutputStream out = connection.openOutputStream();
                            out.write(postData.getBytes());
                            out.flush();
                            out.close();

                            int responseCode = connection.getResponseCode(); //when this code is called, the post data request will be send to server, and after that we can read the response from the server if the response code is 200 (HTTP OK).
                            if(responseCode == HttpConnection.HTTP_OK){
                                //read the response from the server, if the response is ascii character, you can use this following code, otherwise, you must use array of byte instead of String
                                InputStream in = connection.openInputStream();
                                StringBuffer buf = new StringBuffer();
                                int read = -1;
                                while((read = in.read())!= -1)
                                    buf.append((char)read);
                                response = buf.toString();
                            }
                            Dialog.alert("response"+  response);

                            //don’t forget to close the connection
                            connection.close();

                        }catch(Exception e){
                            System.out.println(e.toString()+":"+e.getMessage());
                        }
                    }

Update::

import java.io.IOException;

import javax.microedition.io.HttpConnection;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;

public class UiMainscreen extends MainScreen {
    ButtonField loginButton;
     private static final String TAG_CONTACTS = "contacts";
     private static final String TAG_ID = "id";
     private static final String TAG_NAME = "name";
     private static final String TAG_EMAIL = "email";
     private static final String TAG_ADDRESS = "address";
     private static final String TAG_GENDER = "gender";
     private static final String TAG_PHONE = "phone";
     private static final String TAG_PHONE_MOBILE = "mobile";
     private static final String TAG_PHONE_HOME = "home";
     private static final String TAG_PHONE_OFFICE = "office";
    public UiMainscreen() {


        final ButtonField b=new ButtonField("JSON");
        add(b);

        FieldChangeListener listener=new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                if(field==b){

                    try{    
                    String URL = "http://www.google.co.in/";
                    String METHOD_NAME = "search";
                    String NAMESPACE = "http://tempuri.org/";
                    String SOAP_ACTION = NAMESPACE+METHOD_NAME;

                   SoapObject resultRequestSOAP = null;
                   HttpConnection httpConn = null;
                   HttpTransport httpt;
                   SoapPrimitive response = null;
                   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                   request.addProperty("q", "remoQte");
                   request.addProperty("ie", "UTF-8");
                   System.out.println("The request is=======" + request.toString());
                   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                   envelope.dotNet = true;
                   envelope.setOutputSoapObject(request);

                   httpt = new HttpTransport(URL);
                   httpt.debug = true;
                   try
                   {
                       httpt.call(SOAP_ACTION, envelope);
                       response = (SoapPrimitive) envelope.getResponse();
                       String result =  response.toString();
                       resultRequestSOAP = (SoapObject) envelope.bodyIn;
}
                   catch (IOException e) {
                       // TODO Auto-generated catch block
                       System.out.println("The exception is IO==" + e.getMessage());
                   } catch (XmlPullParserException e) {

                       // TODO Auto-generated catch block
                       System.out.println("The exception xml parser example==="
                               + e.getMessage());
                   }
                   System.out.println( resultRequestSOAP);
                   Dialog.alert("resultRequestSOAP"+resultRequestSOAP);
                    }catch (Exception e) {
                         System.out.println("Problem==="
                                   + e.getMessage());
                    }
            }}
        };
        b.setChangeListener(listener);



    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:58:59+00:00Added an answer on June 9, 2026 at 10:58 am

    Since you want to post some parameters to in your connection, perhaps the following might help.

    String URL = "http://xxx.xxx.com/xxx/xxx.asmx";
    String METHOD_NAME = yourMethodName;
    String NAMESPACE = "http://tempuri.org/";
    String SOAP_ACTION = NAMESPACE+METHOD_NAME;
    SoapObject resultRequestSOAP = null;
    HttpConnection httpConn = null;
    HttpTransport httpt;
    SoapPrimitive response = null;
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("username", user_id);
    request.addProperty("password", password);
    System.out.println("The request is=======" + request.toString());
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    httpt = new HttpTransport(URL+C0NNECTION_EXTENSION);
    httpt.debug = true;
    try
    {
        httpt.call(SOAP_ACTION, envelope);
        response = (SoapPrimitive) envelope.getResponse();
        String result =  response.toString();
        resultRequestSOAP = (SoapObject) envelope.bodyIn;
    }
    catch (IOException e) 
    {
        System.out.println("The exception is IO==" + e.getMessage());
    } 
    catch (XmlPullParserException e) 
    {
        System.out.println("The exception xml parser example==="
        + e.getMessage());
    }
    System.out.println( resultRequestSOAP);
    return response + "";
    

    This is passing two parameters to the webservice; username and password. you can modify accordingly. The Connection Extention is the part where you specify the kind of connection; BES,WIFI etc. Incase of the simulator you can add it as connectionString = ";deviceside=true". This makes use of the Ksoap2 library that you can add in your project via Properties -> Java Build Path -> Library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing one application which need the following functionalities I have webserver. I
Hai every one I am developing an windows application in which i have to
I have been developing Android application which has 3 ListView and one ContextMenu for
I'm developing one AS3 application in which I need to add blank editable box
For an application I'm developing I need a Perl script which loops through a
I'm developing an application for my company in which i need to show one
I'm developing a Mac Application in which i need to implement IPC Mechanism. The
Iam developing one application in Xcode 4.3.I need to run this application on device.Which
I am developing a Tab Bar Application in which My need like I Have
I am developing one application which include the email sending functionality (which is like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.