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

  • This ESG study by Mark Peters evaluated a common industry-standard disk VTl deduplication system (with 15:1 reduction ratio) versus a tape library with LTO-5, drives with full nightly backups, over a five-year period.  The scenarios included replicated systems and offsite tape vaults.  In all circumstances, the TCO for VTL with deduplication ranged from about 2 to 4 times more expensive than the LTO-5 tape library TCO. The paper shares recent ESG research and lots more. 

  • Live Webinar Tuesday, August 26, 2014 1:00 PM EDT Customers are more empowered and connected than ever, and the customer's journey has grown more complex. Their expectations are growing and trust is diminishing as they may interact with multiple brands through web, mobile and social channels. Considering 70% of the buying process in a complex sale is already complete before prospects are willing to engage with a live salesperson -- it's critical to understand your customers and anticipate their needs.* …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds