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 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

Related Questions

i couldn't solve this. when i execute this program i get the following error
I would like execute the following command with Java: C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump -u
I am trying to execute windows commands from Java using the following code, Process
I execute the following: SELECT url FROM mytable WHERE 1 result: url: 'http://www.ciao.es/Epson_Stylus_S22__2007613' Everything
When I execute the following function, I get an error: Error 'Excel1.WebServiceFunctions.CreateMyTask()': not all
When I execute the following query, I get an exception telling me that 'feedItemQuery'
Newbie to C++ learning by converting a java program to c++. The following code
In the following code, am executing a java program Newsworthy_CA. The program prints the
I am confused on the following: To use threads in a Java program, the
I'm trying to get my java program to talk to a MySQL DB. So

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.