Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I really need help with this! In C# write a simple HTTP image browser; i.e. , a Windows forms app which, like an ordinary Web

I really need help with this! image text in transcribed

In C# write a simple HTTP image browser; i.e., a Windows forms app which, like an ordinary Web browser, allows users to enter a URL in a textbox at the top of the window, makes an HTTP request for the resource located at the URL and which, if the URL references an image file; e.g., *.jpg, *.gif, *.png, etc., displays the retrieved image in the browser's Image window.

However, this browser should not only display the image, it should also, in a small window above the image, display the HTTP response line and all HTTP headers received from the server serving the HTTP request. For instance, an HTTP request for http://classes.bus.oregonstate.edu/ba371/reitsma/images/cob.png, results in the following response line and headers being returned by COB's Web server:

HTTP/1.1 200 OK Content-Type: image/png Last-Modified: Wed, 22 Nov 2017 21:46:08 GMT Accept-Ranges: bytes ETag: "a7b8794edb63d31:0" Server: Microsoft-IIS/8.0 X-Powered-By: ASP.NET Date: Mon, 19 Mar 2018 23:39:02 GMT Content-Length: 59587 Length: 59587 (58K) [image/png] 

In addition, we want to distinguish the HTTP response status from the headers and display it in a separate Status code textbox (see example above). Clearly, since we do not know how many headers we will be receiving from the server, we must make the box that lists the returned headers scrollable. Similarly, we want to accommodate for large images. Hence, we want some way of scaling the images or be able to scroll them.

*To make the HTTP request (using the Uri class), you might want to use the System.Net.HttpWebRequest class.

*To get a hold of the HTTP response, you might want to use the System.Net.HttpWebResponse class.

*These HttpWebRequest and HttpWebResponse classes are very rich and powerful. For instance, almost anything you want to know about the HTTP response (its status, does the body contain an image? how many bytes were returned? what are its headers? etc.) is stored on the HttpWebResponse.

*Whenever we have to display images, we have a potential scaling problem; the image is either larger or smaller than the canvas on which we want to display it. Although several ways to deal with the problem exist, a simple (quick and dirty) way to accommodate large images is to embed the PictureBox on which we display the image inside a Panel object and let the Panel object scroll the PictureBox. If we make the PictureBox object larger than the Panel object, set its SizeMode to Autosize and set the Panel's Autoscroll property to true, the Panel will scroll the PictureBox.

*An HTTP timeout (in milliseconds) can be set by using the Timeout attribute of the HttpWebRequest. A five second (5,000 milliseconds) is a good default.

*To make the Enter/Return key work as the Go button, we can do several things. A relatively easy and elegant solution is to write code for the _KeyDown method of the URL textbox which checks to see if the key pressed is the Enter/return key, and if so, calls the method which is normally invoked by the Go button. Something like the following should work:

private void URLTextBox_KeyDown(Object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) goButton_Click(URLTextBox, new EventArgs()); }
Simple HTTP Image Browser Browser Image URL: http// Hlasses bus. oregonstate.edu/ba371/reitsma/mages/cob png Status Code: 200: OK Headers:Connection:close Go Accept-Ranges: bytes Content-Length: 59587 Content-Type: image/png Date: Mon, 19 Mar 2018 23:32:04 GMT ETag: "a7b8794edb 63d31:0" Last-Modified: Wed, 22 Nov 2017 21:46:08 GMT Simple HTTP Image Browser Browser Image URL: http// Hlasses bus. oregonstate.edu/ba371/reitsma/mages/cob png Status Code: 200: OK Headers:Connection:close Go Accept-Ranges: bytes Content-Length: 59587 Content-Type: image/png Date: Mon, 19 Mar 2018 23:32:04 GMT ETag: "a7b8794edb 63d31:0" Last-Modified: Wed, 22 Nov 2017 21:46:08 GMT

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions