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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:47:18+00:00 2026-05-13T07:47:18+00:00

When I execute the following java program, sometimes I get an empty response ,

  • 0

When I execute the following java program, sometimes I get an empty response, sometimes I get the real (redirected) content.

ByteArrayOutputStream output = new ByteArrayOutputStream();
URL url = new URL( "https://stackoverflow.com/questions/84629" );
IOUtils.copy( url.openStream(), output );
System.out.println( output.toString() );

The URL https://stackoverflow.com/questions/84629 is a redirect to What's your favorite "programmer" cartoon?.

I looked through other SO questions and tried to use the suggested HttpUrlConnection, but the result was the same. The response code is always 200, but sometimes there is the correct html output, sometimes it’s just an empty string.

Can you explain what is happening here?


EDIT

Here’s the code without Apache commons:

ByteArrayOutputStream output = new ByteArrayOutputStream();
URL url = new URI( "https://stackoverflow.com/questions/84629" ).toURL();
InputStream openStream = url.openStream();
byte[] buffer = new byte[ 1024 ];
int size = 0;
while( (size = openStream.read( buffer ) ) != -1 ) {
    output.write( buffer, 0, size );
}
System.out.println( output.toString() );

I’m using Windows XP and Java 1.6.0_17.


I captured the traffic using wireshark:

GET /questions/84629 HTTP/1.1
User-Agent: Java/1.6.0_17
Host: stackoverflow.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

HTTP/1.1 200 OK
Cache-Control: private
Server: Microsoft-IIS/7.0
Date: Tue, 10 Nov 2009 22:42:42 GMT
Content-Length: 0
  • 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-13T07:47:18+00:00Added an answer on May 13, 2026 at 7:47 am

    I think it’s like @carl-smotricz said: “You’re probably running up against a spam filter or something.”

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT RepaymentDay, SUM(MonthlyRepaymentAmount) AS MonthlyRepaymentAmount FROM YourTable GROUP BY RepaymentDay… May 16, 2026 at 6:01 pm
  • Editorial Team
    Editorial Team added an answer Makes no difference. Choose one and stick with it. So… May 16, 2026 at 6:01 pm
  • Editorial Team
    Editorial Team added an answer Use the above answer if you just want a single… May 16, 2026 at 6:01 pm

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

I want to execute a batch file from a java program. I am using
At the moment I execute a native process using the following: java.lang.Process process =
Consider the following script: println ls -l.execute().text Why do I get the following error
When I execute the following query on a database containing a table comm_list and
I have a java program that generates an HTML file. The Java program takes
I'm trying to send keystrokes from my C# program to a Java application The
I'm a newbie to Java-related web development, and I can't seem to get a
I have a Java program with code: public class Test1 { public static void
I want to get the file name without the file extension in Vim. I
I am creating breakpoints to debug my java application , and am using netbeans

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.