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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:39:30+00:00 2026-05-14T01:39:30+00:00

I am using a lot of HTTP Requests in an application that I am

  • 0

I am using a lot of HTTP Requests in an application that I am writing which uses OAuth. Currently, I am sending my GET and POST requests the same way:

HttpConnection connection = (HttpConnection) Connector.open(url
                    + connectionParameters);

            connection.setRequestMethod(method);
            connection.setRequestProperty("WWW-Authenticate",
                    "OAuth realm=api.netflix.com");

            int responseCode = connection.getResponseCode();

And this is working fine. I am successfully POSTing and GETing. However, I am worried that I am not doing POST the right way. Do I need to include in the above code the following if-statement?

if (method.equals("POST") && postData != null) {
                    connection.setRequestProperty("Content-type",
                            "application/x-www-form-urlencoded");
                    connection.setRequestProperty("Content-Length", Integer
                            .toString(postData.length));
                    OutputStream requestOutput = connection.openOutputStream();
                    requestOutput.write(postData);
                    requestOutput.close();
                }

If so, why? What’s the difference? I would appreciate any feedback.

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-14T01:39:30+00:00Added an answer on May 14, 2026 at 1:39 am
    connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
    

    The content type must match the actual format of the postData. A content type of application/x-www-form-urlencoded is only necessary if the content type is actually url encoded. E.g. you’re encoding POST data as follows:

    String data = "param1=" + URLEncoder.encode(param1, "UTF-8")
               + "&param2=" + URLEncoder.encode(param2, "UTF-8");
    

    This way the other side will be able to parse the data according the specified format without breaking it.

    And,

    connection.setRequestProperty("Content-Length", Integer.toString(postData.length));
    

    This is preferable to ensure a robust data transfer. If you omit this and the connection somehow get broken, then the other side will never be able to determine if the content is fully streamed in or not.

    That said, the cast to HttpUrlConnection is unnecessary if you know the fact that the request method will “automatically” be set to POST if you do:

    connection.setDoOutput(true);
    

    or in your case more suitable:

    connection.setDoOutput("POST".equals(method));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application that makes a lot of http requests and then
I'm building a server application that needs to perform a lot of http requests
I'm using a lot of JQuery in a web application that I am building
I've written a web application using Catalyst that has a lot of forms and
I have an application which logs into an online site using POST form being
I'm using the tabs in jQuery UI : http://jqueryui.com/demos/tabs/ I've actually a lot of
I've been using a lot of new .NET 3.5 features in the work that
I am profiling an application suddenly using a lot of memory, and i am
We have several applications that use Apache HTTPClient 3 to make HTTP requests. Recently
I'm building a non-browser client-server (XULRunner-CherryPy) application using HTTP for communication. The area I'm

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.