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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:52:48+00:00 2026-05-16T09:52:48+00:00

I was working on HTTP post using java and encountered a weird stream behavior.

  • 0

I was working on HTTP post using java and encountered a weird stream behavior. Here’s what happened:

Func() {
    String data = “MyMessage”
    URL url = new URL("http://edsall:8080"); 
    URLConnection conn = url.openConnection(); 
    conn.setDoOutput(true); 

    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    wr.write(data); 
    wr.flush();         

    // Get the response 
    String line; 
    while ((line = rd.readLine()) != null) { 
    } 

    wr.close();
    rd.close();
}

Request recvd by the server:
POST / HTTP/1.1
User-Agent: Java/1.6.0_20
Host: edsall:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-type: application/x-www-form-urlencoded
Content-Length: 0

Observe that the content length is always 0. Initially, I couldn’t figure out what the problem was. Finally, the following re-arrangement of code did the trick:

Func() {
    …
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
    wr.write(data); 
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    …
}

I am not able to understand this clearly. How does opening a handle to the input stream affect the output stream?

  • 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-16T09:52:49+00:00Added an answer on May 16, 2026 at 9:52 am

    Opening the input stream (or querying the status) “commits” the request—i.e., the request is sent to the server.

    I’m not sure what happened to the data that you wrote to the output stream (I would have hoped for an exception if it didn’t actually get sent), but the content-length header is sent (with a length of zero) when getInputStream() is called.

    The entire request must be sent before accessing any part of the response. This is normal URLConnection behavior.

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

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can add custom prerequisites to bootstrap any redistributable package.… May 17, 2026 at 12:11 am
  • Editorial Team
    Editorial Team added an answer The remedy is in two parts and you MUST action… May 17, 2026 at 12:11 am
  • Editorial Team
    Editorial Team added an answer I found my problem. It wasn't a bug in the… May 17, 2026 at 12:11 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is it possible to resume interrupted uploads using HTTP Post? I am working on
I having an issue from my HTTP Post. The code I'm using are working
I'm stuck trying to get a WinInet HTTP POST via SSL using ONLY C.
I am using CakePHP v1.2 for my web application hosted here: http://lol-land.in The application
I am working on Java. I am calling a GET url on my own
I am working on a module that allows users to post comments on a
I'm working with a Droid / Android 2.0.1 and encountering an issue apparently many
I am using swfupload, and have a bunch of 'Attach File' links and each
I am working on an applet that interfaces with a signature pad. The signature
Seems like both EnyimMemcached ( https://github.com/enyim/EnyimMemcached ) and BeITMemcached ( http://code.google.com/p/beitmemcached/ ) are popular

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.