HTTP Test



Click here for a larger image.

Environment: VS7 C# .NET

I wrote this application to see what the HttpWebRequest and HttpWebResponse classes did. I am not a Web programmer and I'm not that familiar with HTTP or HTML, so I wanted to see what these function do. I'm sure someone else who has a more intimate knowledge of these protocols could do a lot more. I was unsure of what I was seeing, which is why I wrote WebPageGet.

private void GetButtonClick(object sender, System.EventArgs e)
{
HttpWebRequest httpReq;
HttpWebResponse httpResp;
Stream httpStream;

  m_results.Text = "";
  MessageBeep(100);
try
{
  ASCIIEncoding ASCII = new ASCIIEncoding();
  byte[] buf = new byte[ 128000 ];
  m_header_list.Items.Clear();
  httpReq    = (HttpWebRequest)WebRequest.Create(m_url.Text);
  httpResp   = (HttpWebResponse)httpReq.GetResponse();
  httpStream = httpResp.GetResponseStream();
  int count  = httpStream.Read(buf, 0, buf.Length);
  httpStream.Close();

  string tempstr = ASCII.GetString(buf, 0, count);
  ChangeLfToCrLf(ref tempstr);
  m_results.Text = tempstr;
  for(int i=0; i < httpResp.Headers.Count; ++i)
    m_header_list.Items.Add( httpResp.Headers.Keys[i] + " = " 
                             + httpResp.Headers[i]);
  for(int i=0; i< httpResp.Cookies.Count; i++)
    m_cookie_list.Items.Add( httpResp.Cookies[i]);

}
catch (Exception except)
{
  m_results.Text = "Generic Exception: {0}" 
                 + except.Message.ToString();
}
  MessageBeep(10000);
}

Downloads

Download source - 21 Kb


Comments

  • You will never got cookies list, need fix.

    Posted by Legacy on 07/25/2003 12:00am

    Originally posted by: ros

    Hallo!

    Tanks for useful program, but after WebRequest object is created it's necessary to initialize CookieContainer property. If it's not done, then amount of cookies will be always 0.

    Solution: After WebRequest.Create add string:
    httpReq.CookieContainer = new CookieContainer();

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

  • Confused by all the agile advice? Relax! With the Agile for Dummies eBook by your side you'll learn the fundamentals of agile and how to increase the productivity of your software teams while enabling them to produce higher-quality solutions that better fulfill customer needs much faster.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds