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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:53:42+00:00 2026-05-26T06:53:42+00:00

** Update I have a solution below, but it’s rather manual… if there is

  • 0

** Update I have a solution below, but it’s rather manual… if there is an easier way, I’d prefer that answer.

I want to record execution and download time of a webpage, and I am trying to use the WebClient.DownloadDataAsync method to post data to a page and get a result.

I know there are numerous ways to post using WebClient or WebRequest objects, but none of them dispatch the DownloadProgressChanged event. This event is key, as I want to track progress of the download, which is in the area of 30 megs+.

I figure the best way to do this would be to construct the header manually, but I’m hitting a dead-ends. Mainly, I cannot add the data to the request.

WebClient client = new WebClient();
//!!!!*****no idea how to add the following data to the request
string data = "test1=value"; 
client.Headers.Add( "POST", "/About.aspx HTTP/1.1" );
client.Headers.Add( "Host", "http://localhost:12065" );
client.Headers.Add( "Content-Type", "application/x-www-form-urlencoded" );
client.Headers.Add( "Content-length", data.Length.ToString() );

client.DownloadProgressChanged += OnDownloadProgressChanged;
client.DownloadDataCompleted += OnDownloadDataCompleted;
client.DownloadDataAsync( new Uri( "http://localhost:12065/About.aspx" ) );

I am open to other solutions, or getting the header in this example to work as if the client is sending a POST.

  • 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-26T06:53:42+00:00Added an answer on May 26, 2026 at 6:53 am

    OK… well I figured out a way to do this using WebRequest. It’s a little more complicated, but it does the trick. I am surprised that WebClient doesn’t do this already, but it seems as though WebClient has a number of unexpected issues.

    //Using System.Diagnostics, set up a Stopwatch to time the execution
    Stopwatch stopWatch = new Stopwatch();
    stopWatch.Start();
    
    //convert your post data into a byte array... we're dealing with streams here
    byte[] postData = Encoding.ASCII.GetBytes( postData );
    
    //We're using the WebRequest object found in System.Net to do our work for us
    WebRequest request = WebRequest.Create( url );
    
    //Set all your headers
    request.ContentType = "application/x-www-form-urlencoded";
    request.Method = "POST";
    request.ContentLength = postData.Length;
    
    //set up your request stream and write out your post data
    Stream stream = request.GetRequestStream();
    stream.Write( postData, 0, postData.Length );
    stream.Close();
    
    //Send the data and wait for a response. [blocking operation]
    WebResponse response = request.GetResponse();
    
    //Once you reach this line, the server has finished doing it's work, 
    //and downloading has commenced
    Console.WriteLine( "First Response: {0}", stopWatch.Elapsed );
    
    //Start timing the download, wouldn't it be nice is there was a restart method? (.Net 4.0)
    stopWatch.Reset();
    stopWatch.Start();
    
    //We want to receive the data. so ask for the response stream
    Stream reponseStream = response.GetResponseStream();
    
    //In my case, there are megabytes of information, so the console is no good,
    //I'll store it in a file.
    FileStream fileStream = File.Open( "result.txt", FileMode.OpenOrCreate );
    
    //create a buffer to collect data as it is downloaded
    byte[] buffer = new byte[1024];
    
    //This loop will run as long as the responseStream can read data. (i.e. downloading data)
    //Once it reads 0... the downloading has completed
    int resultLength;
    while( ( resultLength = reponseStream.Read( buffer, 0, buffer.Length ) ) != 0 )
    {
        //You could further measure progress here... but I don't care.
        fileStream.Write( buffer, 0, resultLength );
    }
    
    //Everything is done... how long did it take to download?
    Console.WriteLine( "Download Complete: {0}", stopWatch.Elapsed );
    
    //housekeeping
    fileStream.Flush();
    fileStream.Close();
    stopWatch.Stop();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update I have posted my solution to this problem as an answer below. It
Update: Solution below Say you have a list of selected items from Finder. Say
UPDATE I tried Crazy's solution but now I have problem showing data in a
I know that there must be a really simple solution to the below problem
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
I have an UPDATE sql command that modifies a Date/Time field in a particular
I have some update or something that tries to run every night, and ends
I have an update query being run by a cron task that's timing out.
I have an UPDATE statement that's intended to update a status field for a
SOLVED: See my solution below! using aspx with C# code behind. I have the

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.