However, this browser should not only display the image, it should also, in a sm
ID: 3702441 • Letter: H
Question
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:
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).
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 GMTExplanation / Answer
Program:
using System;
using System.Drawing;
using System.IO;
// input and output devices
using System.Net;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string sURL = textBox1.Text;
WebRequest req = WebRequest.Create(sURL);
WebResponse res = req.GetResponse();
string headers = res.Headers.ToString();
Stream imgStream = res.GetResponseStream();
Image img1 = Image.FromStream(imgStream);
imgStream.Close();
pictureBox1.Image = img1;
richTextBox1.Text = headers;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.