Sean
Sean

Reputation: 963

Sending a JSONObject to a URL

I have an application which parse data from a localhost, I send one of the data (named stuff) to another activity (named WView). Now, In my second activity (WView), I want to send stuff to another link. I used ArrayList<NameValuePair> to send stuff for the first time to localhost, and then I changed the object to a string name stuff just for the purpose of testing.

Now, the problem is, I'm using the following code. "add" in postParameters.add(stuff.toString()); , has an error.

So tell me if I'm using the write way, or if it is wrong, tell me how to make it right. I paste my code for sending stuff, from WView to another link.

btLogout.setOnClickListener( new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(stuff.toString());
            String response = null;

              // call executeHttpPost method passing necessary parameters 
              try {
         response = CustomHttpClient.executeHttpPost("http:example.com", postParameters);
              }
              catch (Exception e) {
                     Log.e("log_tag","Error in http connection!!" + e.toString());     
                    }

        }
    });

Upvotes: 0

Views: 94

Answers (1)

KOTIOS
KOTIOS

Reputation: 11194

Correct Syntax is :

    postParameters.add(new BasicNameValuePair("key", Value));

In your case you need to change to :

    postParameters.add(new BasicNameValuePair("stuff", stuff.toString()));

Upvotes: 1

Related Questions