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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:23:47+00:00 2026-05-26T15:23:47+00:00

When downloading a file with HttpWebResponse the content length sent by the server is

  • 0

When downloading a file with HttpWebResponse the content length sent by the server is wrong and causes the HttpWebResponse to stop downloading the file mid-way through. IE seems to not have this issue when you browse. Any idea on how to get HttpWebResponse to ignore the content length the sever sent or would that even make sense.
Any help that could be given would be greatly appreciated.

–Example

class Program
{
    static void Main(string[] args)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:59771/Default.aspx");
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        Console.WriteLine("Content length: " + response.ContentLength);

        int bytesRead = 0;
        long totalBytesRead = 0;

        byte[] data = new byte[1024 * 64];
        StringBuilder output = new StringBuilder();

        Stream responseStream = response.GetResponseStream();

        do
        {
            bytesRead = responseStream.Read(data, 0, 1024 * 64);
            totalBytesRead += bytesRead;

            output.Append(Encoding.ASCII.GetString(data, 0, bytesRead));
        }
        while (bytesRead > 0);

        Console.WriteLine("total read: " + totalBytesRead);
        Console.WriteLine("last content read: " + output.ToString());
    }

    protected void Page_Load(object sender, EventArgs e)
    {
       Response.Clear();
       Response.ClearHeaders();
       Response.AddHeader("Content-Length", "13");
       Response.Write("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }
}

Problem SOLVED!

The server we are pulling the data down from is a Cognos server and it was calculating the content length as if the string was to be compressed, but we were not sending in the code to state we could accept compression, so it would send back uncompressed data but only to the length of the compression. IE did not have this issue as it stated it could accept compression.
Code to correct issue:

request2.Headers.Add("Accept-Encoding", "gzip,deflate");
  • 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-26T15:23:47+00:00Added an answer on May 26, 2026 at 3:23 pm

    Problem SOLVED!

    The server we are pulling the data down from is a Cognos server and it was calculating the content length as if the string was to be compressed, but we were not sending in the code to state we could accept compression, so it would send back uncompressed data but only to the length of the compression. IE did not have this issue as it stated it could accept compression. Code to correct issue:

     request2.Headers.Add("Accept-Encoding", "gzip,deflate"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am downloading a file from the server/database via aspx page. When using the
I just want to confirm something I noticed when downloading a file through sftp
Referencing my Earlier Question , regarding downloading a file from a server and handling
hi i am downloading file from server using ASIHTTPRequest in my iphone application but
I am using ASIHTTPRequest for downloading file from server but its giving error Failed
Before downloading a file from ftp server, I want to check it if exist
I implemented a tree with an outputResource as content (see Downloading file from IceFaces
I am downloading a file from an ftp server and saving it to the
When downloading file from server if i use a4j:commandLink file download fail(mean file written
I'm downloading a file using QNetworkAccessManager::get but unlike QHttp::get there's no built-in way 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.