Click here to Skip to main content
15,671,597 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have this question and I am not able to figure it out.

Bulk Download:

The application should provide a bulk download facility as follows. The user should be able specify a file name, default setting bulk.txt, containing URLs (exactly one per line).

When initiating bulk download, the application should retrieve each of the pages listed in the file, and display the results as a list of lines as follows: code bytes URL

where code should be the response status code from the page retrieval, bytes should be the number of bytes retrieved from this URL, and URL should be the URL as specified in the bulk download file.

These results should be shown in a textarea.

What I have tried:

I have manged to do this but I don't think I know how to display it.

Bulk.txt has 5 lines of text with some website URL's

private async void button2_Click(object sender, EventArgs e)
           string path = "C:bulk.txt";
           StreamReader stream = new StreamReader(path);
           string mydata = stream.ReadToEnd();
          label1.Text = mydata.ToString();

           using (var client = new HttpClient())
           using (HttpResponseMessage response = await client.GetAsync(""))
               byte[] fileContents = await response.Content.ReadAsByteArrayAsync();
               richTextBox1.Text = fileContents.ToString();
Richard MacCutchan 16-Oct-21 8:20am    
You read the text file's content but then do not use those URLs as specified in the instructions.

Also look at the following:
          string mydata = stream.ReadToEnd();
          label1.Text = mydata.ToString();

Why are you calling ToString on a value that is already a string?

The instructions are clear:
- Read each line from the text file one at a time.
- Use the URL just read to capture some data from the internet.
- Display the HTTP status code, the number of bytes returned and the URL.
- Repeat until all lines processed.
candijen 16-Oct-21 8:38am    
I do not know how to get the number of bytes returned and display it
Richard MacCutchan 16-Oct-21 9:09am    
You need to examine the response returned from each HTTP request.
candijen 16-Oct-21 9:23am    
Currently I tried from a single request like but it displays System.bytes[] in my textbox.
Richard MacCutchan 16-Oct-21 9:42am    
You need to convert the contents to its string representation by the use of the Encoding Class (System.Text) | Microsoft Docs[^]. But you should not really be doing this, the instructions tell you just to print the status code, and the number of bytes returned. The actual response text will be a few pages long.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900