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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:52:29+00:00 2026-05-27T18:52:29+00:00

I trying to make http – post call. The server that i send him

  • 0

I trying to make http – post call.
The server that i send him this request need to have two parameters
1. first parameter is Int
2. second parameter is enum that i sending as string

I try to do it in two ways and them both fail:

First way:

 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
 nameValuePairs.add(new BasicNameValuePair("intVal", "-100")); 
 nameValuePairs.add(new BasicNameValuePair("enumVal", "enumAsString"));  
 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

I get ‘bar request’ as a response.

Second way:

      DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(SERVER_ADDRESS + METHOD_NAME);
try
{
     HttpParams postParams = new BasicHttpParams();
           postParams.setIntParameter("intVal", -100 ); 
           postParams.setParameter   ("enumVal" , "enumAsString" ); 

           httppost.setParams(postParams);

           HttpResponse p = httpclient.execute(httppost);
      }
      catch(Exception e) 
      {

                  .... 

      }

In this way i see that the server get the parameters – but the first parameter ( that need to be int ) is 0 and the second parameter ( that need to be enum ) is 0 also.

P.S : The code that run on the server is WCF code – using REST.

Please .. i must solve this issue …

Thanks.

  • 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-05-27T18:52:30+00:00Added an answer on May 27, 2026 at 6:52 pm

    Here is two different ways which you can send param with HttpPost and HttpUrlConnection using Andorid :

    First Way :

    HttpClient httpclient;
    HttpPost httppost;
    ArrayList<NameValuePair> postParameters;
    httpclient = new DefaultHttpClient();
    httppost = new HttpPost("your login link");
    
    
    postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("param1", "param1_value"));
    postParameters.add(new BasicNameValuePair("param2", "param2_value"));
    
    httppost.setEntity(new UrlEncodedFormEntity(postParameters));
    
    HttpResponse response = httpclient.execute(httppost);
    

    The second way is :

            String charset = "UTF-8";
        String query = String.format("debug_data=%s&"
                                + "client_auth_hash=%s&" 
                                + "timestamp=%s&"
                                + "client_api_ver=%s&",
                                URLEncoder.encode("1", charset),
                                URLEncoder.encode(hash, charset),
                                URLEncoder.encode(timeStamp, charset),
                                URLEncoder.encode(clientApiVersion, charset));
    
            System.setProperty("http.keepAlive", "false");
            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
            connection.setDoOutput(true);
            connection.setConnectTimeout(5000); //miliseconds
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Charset", charset);
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
            OutputStream output = null;
            try {
                output = connection.getOutputStream();
                output.write(query.getBytes(charset));
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (output != null)
                    try {
                        output.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
    
            int status = ((HttpURLConnection) connection).getResponseCode();
            Log.d("", "Status : " + status);
    
            for (Entry<String, List<String>> header : connection
                    .getHeaderFields().entrySet()) {
                Log.d("Headers",
                        "Headers : " + header.getKey() + "="
                                + header.getValue());
            }
    
            InputStream response = new BufferedInputStream(connection.getInputStream());
    
            int bytesRead = -1;
            byte[] buffer = new byte[30 * 1024];
            while ((bytesRead = response.read(buffer)) > 0) {
            //read the response in pieces if it's needed
                byte[] buffer2 = new byte[bytesRead];
            }
            connection.disconnect();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    

    The both ways are working properly.

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

Sidebar

Related Questions

I'm trying to make a simple HTTP POST request, and I have no idea
I'm trying to make a request to a website this way : file_get_contents('http://www.yahoo.com/index.php?var=value'); in
I'm trying to make a HTTP request through an open SOCKS5 proxy. I have
I am trying to make an Http POST to an Apache web server. I
I am trying to make Apache send: http://mydomain.com/these/are/arguments/mmmk to: http://mydomain.com/?pages=these/are/arguments/mmmk Such that $_GET['pages'] will
I am trying to make a simple request using http.get. But I need to
I'm trying to make a http request. The code looks like this: NSString *urlString
I'm trying to make simple http server, that can be pause and resume,, I've
I have this test page: http://www.problemio.com/index_new.php and I am trying to make some jQuery
I am trying to make a simple HTTP server that would be able to

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.