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 8338831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:42:50+00:00 2026-06-09T04:42:50+00:00

I am making an application for android, i need to make a request to

  • 0

I am making an application for android, i need to make a request to http://www.example.com address using java. the problem is that I need to send POST parameters and i’ve been searching some info and i found something about cross-domain or something like that. Could someone help me to get to the request and get answer?

I tried to do the following code but not working:

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://www.example.com");

try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    nameValuePairs.add(new BasicNameValuePair("param1", "val"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}

SOLUTION:::::::::::::

  try {
                HttpClient client = new DefaultHttpClient();
                HttpPost post = new HttpPost("http://www.example.com");

                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();

                postParameters.add(new BasicNameValuePair("key", "val"));
                postParameters.add(new BasicNameValuePair("key2", "val2"));


                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
                        postParameters);
                post.setEntity(formEntity);

                    HttpResponse response = client.execute(post);
                        //inputStreamToString method
                    String data = inputStreamToString(response.getEntity()
                            .getContent());
                    return data;
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

inputStreamToString Method

private String inputStreamToString(InputStream is) {
        String s = "";
        String line = "";

        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));

        // Read response until the end
        try {
            while ((line = rd.readLine()) != null) {
                s += line;
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // Return full string
        return s;
    }
  • 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-09T04:42:52+00:00Added an answer on June 9, 2026 at 4:42 am

    Cross-domain POST applies to web browsers submitting forms, not to HTTP in general. Browsers will not post across domains as a security policy. It does not apply to your case.

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

Sidebar

Related Questions

I am making an android application and as a part of that I need
I am making an android application that loads files from a directory on the
I'm making an android application using phonegap. I'm using phonegap's Storage api for querying
I am making an android application that will play an mp3 file once a
I am making an android application that needs to display all of the items
I am making an android application that uses a listview. I want to get
I'm making an Android application where I need to slow down the audio being
I am using a SQLite to store data in Android application . I need
I'm writing an application (on android) that uses both java code, and native code.
I am trying to make an Application, that is posible to send SMS, 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.