All pastes #420998 Raw Edit

UTAD

public text v1 · immutable
·published 2007-04-02 15:15 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WebClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            headerslistBox.Items.Clear();
            cookieslistBox.Items.Clear();
            responselistBox.Items.Clear();

            HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create("http://"+urlBox.Text);
            hwr.UserAgent = "DAWEB Test Browser";
            hwr.CookieContainer = new CookieContainer();
            HttpWebResponse hwrsp= (HttpWebResponse) hwr.GetResponse();
            WebHeaderCollection whc = hwrsp.Headers;
            String servertype = hwrsp.Server.ToString();
            String contenttype = hwrsp.ContentType.ToString();


            for (int i = 0; i < whc.Count; i++)
            {
                headerslistBox.Items.Add(whc.GetKey(i) + "=" + whc.Get(i));
            }

            hwrsp.Cookies = hwr.CookieContainer.GetCookies(hwr.RequestUri);
            foreach (Cookie cky in hwrsp.Cookies)
            {
                cookieslistBox.Items.Add(cky.Name + "=" + cky.Value);
            }

            Stream strm = hwrsp.GetResponseStream();
            StreamReader sr = new StreamReader(strm);
            if (servertype.Contains("Apache"))
            {
                if ( contenttype.Contains("text"))
                {
                    responselistBox.Items.Add(sr.ReadLine());
            while (sr.Peek() > -1)
            {
                    responselistBox.Items.Add(sr.ReadLine());
             }
         }
         else
         {
             responselistBox.Items.Add("O browser apenas suporta conteudo \"text\"");
         }

         }
         else
         {
             responselistBox.Items.Add("Servidor não permitido!");
         }

            sr.Close();
            strm.Close();
        }




    }
}