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

  • Adaptation and evolution are fundamental requirements of survival -- not only in nature, but also in business. Our world has changed dramatically in a short amount of time. Many businesses are fueling and capitalizing on this change, while others are desperately clinging to a bygone era. Who is left standing in the years and decades ahead should come as no surprise. This edition of Unleashing IT highlights the companies that are embracing new circumstances, new methods, and new opportunities. By downloading …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds