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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

Most Popular Programming Stories

More for Developers

RSS Feeds