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

  • SEARCH
  • Home
  • 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 8263921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:16:19+00:00 2026-06-08T04:16:19+00:00

I have an application built that works like a form, it takes four fields

  • 0

I have an application built that works like a form, it takes four fields and validates the information in order to make sure that no invalid characters are entered. These four fields are stored in variables:

  • Phone
  • Name
  • Email
  • Comments

    Now I want to submit the form data (whatever is entered into these four fields and stored to the variables) to a url (will use http://www.test.com), but I am not sure how to go about doing this. I think I am looking for something called the HttpURLConnection, but I am not sure how to specify which variable is sent. The code below I found from the website http://developer.android.com/reference/java/net/HttpURLConnection.html

    private class UploadFilesTask extends AsyncTask<URL, Integer, Long>{
    protected Long doInBackground(URL... urls) {
    
        try {
            HttpClient http = new DefaultHttpClient();
            HttpPost post = new HttpPost("http://www.test.com");
    
            List<NameValuePair> data = new ArrayList<NameValuePair>();
            data.add(new BasicNameValuePair("phone", "value"));
            data.add(new BasicNameValuePair("name", "value"));
            data.add(new BasicNameValuePair("email", "value"));
            data.add(new BasicNameValuePair("comments", "value"));
            post.setEntity(new UrlEncodedFormEntity(data));
    
            HttpResponse response = http.execute(post);
            // do something with the response
        }
        catch (ClientProtocolException e) {
            // do something
            finish();
        }
        catch (IOException e) {
            // do something
            finish();
        }
    

    }

    }

Any help would be much appreciated, thank you!

  • 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-08T04:16:22+00:00Added an answer on June 8, 2026 at 4:16 am

    The simplest way to send form data to a server is to use HttpClient, and HttpPost.

    Try something like this:

    try {
        HttpClient http = new DefaultHttpClient();
        HttpPost   post = new HttpPost("http://www.example.com/process");
    
        List<NameValuePair> data = new ArrayList<NameValuePair>();
        data.add(new BasicNameValuePair("phone", "value");
        data.add(new BasicNameValuePair("name", "value");
        data.add(new BasicNameValuePair("email", "value");
        data.add(new BasicNameValuePair("comments", "value");
        post.setEntity(new UrlEncodedFormEntity(data));
    
        HttpResponse response = http.execute(post);
        // do something with the response
    }
    catch (ClientProtocolException e) {
        // do something
    }
    catch (IOException e) {
        // do something
    }
    

    Note, you’ll want to perform this operation in an AsyncTask so you don’t lock up the UI thread waiting for the networking operations to complete.

    Edit

    Here’s a simple quick example of what it might look like in an AsyncTask.

    public class SendTask extends AsyncTask<Void, Void, Boolean> {
    
        String responseString;
    
        @Override
        protected Boolean doInBackground(Void... params) {
            try {
    
                HttpClient http = new DefaultHttpClient();
                HttpPost post = new HttpPost("http://www.test.com");
    
                List<NameValuePair> data = new ArrayList<NameValuePair>();
                data.add(new BasicNameValuePair("phone", "value"));
                data.add(new BasicNameValuePair("name", "value"));
                data.add(new BasicNameValuePair("email", "value"));
                data.add(new BasicNameValuePair("comments", "value"));
                post.setEntity(new UrlEncodedFormEntity(data));
    
                HttpResponse response = http.execute(post);
                responseString = new BasicResponseHandler().
                                     handleResponse(response); // Basic handler
                return true;
            }
            catch (ClientProtocolException e) {
                // do something useful to recover from the exception
                // Note: there may not be anything useful to do here
            }
            catch (IOException e) {
                // do something useful to recover from the exception
                // Note: there may not be anything useful to do here
            }           
            return false;
        }
        @Override
        protected void onPostExecute(Boolean success) {
            // TODO: Do something more useful here
            if (success) {
                Toast.makeText(MainActivity.this, "Success: " + responseString, Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(MainActivity.this, "Failed", Toast.LENGTH_LONG).show();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a Java application that has some dependencies (~10). I would like
I have a PHP application that is built around the MVC architecture without any
We have an application that we have built as a bundle and we want
I have this consumer targeted application that has built in error reporting. Sometimes I
I have a layered web application that I built with ASP.NET MVC 4, WebAPI
I have an application that will accept URLs from the built in web browser
I have an application that runs on a client's server built on a SQL
I have an already built application and I want to add a feature that
We have built a web application that accepts SOAP messages, does some processing, calls
I have built so far an application that allows the user to drag and

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.