Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Get that server allow auto redirect – write stream buffering - get connection and group name using HttpWebRequest class C#.net – vb.net.

Author: Shehzad Hemani
Download Source Code : 995_HtmlDocument.zip

In this simple article you will learn that how we can get that server allow auto redirect, allow write stream buffering and how we can get connection http header value and group name.

 To perform the above mentioned operations first of all you will have to make a request to the server for this we have a class httpwebrequest. This class makes request to the server and httpwebresponse get the response from the server. How these classes work I have discussed this in one of my previous articles which has title “Get html source of web page using HttpWebRequest class C#.net – vb.net.

Connection header value:

To get the value of connection http header from server we have a property of HttpWebRequest class named connection. This property takes and returns a string value. This is the http header value of connection.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_connection_Click(object sender, EventArgs e)

        {

            try

            {

                string url = string.Empty;

                url = txt_url.Text;

                if (url == string.Empty)

                {

                    MessageBox.Show("Enter valid url");

                }

                else

                {

                    HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

                    myWebRequest.Method = "GET";

                    HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

                    MessageBox.Show(myWebRequest.Connection);

                }

            }

            catch (Exception ex) { MessageBox.Show("invalid entry"); }

        }

VB

Private Sub btn_connection_Click(ByVal sender As Object, ByVal e As EventArgs)

        Try

            Dim url As String = String.Empty

            url = txt_url.Text

            If url = String.Empty Then

                MessageBox.Show("Enter valid url")

            Else

                Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)

                myWebRequest.Method = "GET"

                Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)

                MessageBox.Show(myWebRequest.Connection)

            End If

        Catch ex As Exception

            MessageBox.Show("invalid entry")

        End Try

    End Sub

This is simple code to get value of connection http header.

Get connection group for request:

To get the connection group name for request from server we have a property of HttpWebRequest class named connection group name. This property takes and returns a string value.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_groupname_Click(object sender, EventArgs e)

        {

            try

            {               

                url = txt_url.Text;

                if (url == string.Empty)

                {

                    MessageBox.Show("Enter valid url");

                }

                else

                {

                    HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

                    myWebRequest.Method = "GET";

                    myWebRequest.ConnectionGroupName = "DEVASP";

                    HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

                    MessageBox.Show(myWebRequest.ConnectionGroupName);

                    myWebRequest.Abort();

                    myWebResponse.Close();

                }

            }

            catch (Exception ex) { MessageBox.Show("invalid entry"); }

        }

VB

Private Sub btn_groupname_Click(ByVal sender As Object, ByVal e As EventArgs)

        Try

            url = txt_url.Text

            If url = String.Empty Then

                MessageBox.Show("Enter valid url")

            Else

                Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)

                myWebRequest.Method = "GET"

                myWebRequest.ConnectionGroupName = "DEVASP"

                Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)

                MessageBox.Show(myWebRequest.ConnectionGroupName)

                myWebRequest.Abort()

                myWebResponse.Close()

            End If

        Catch ex As Exception

            MessageBox.Show("invalid entry")

        End Try

    End Sub

This is simple code to get connection group name for request.

Allow Auto Redirect:

To get that request should follow the redirect responses or not for this purpose we have a property of HttpWebRequest class named AllowAutoRedirect. This property takes and returns a Boolean value.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_autoredirect_Click(object sender, EventArgs e)

        {

            try

            {

                url = txt_url.Text;

                if (url == string.Empty)

                {

                    MessageBox.Show("Enter valid url");

                }

                else

                {

                    HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

                    myWebRequest.Method = "GET";

                    HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

                    bool b = myWebRequest.AllowAutoRedirect;

                    MessageBox.Show(b.ToString());

                    myWebRequest.Abort();

                    myWebResponse.Close();

                }

            }

            catch (Exception ex) { MessageBox.Show("invalid entry"); }

        }

VB

Private Sub btn_autoredirect_Click(ByVal sender As Object, ByVal e As EventArgs)

        Try

            url = txt_url.Text

            If url = String.Empty Then

                MessageBox.Show("Enter valid url")

            Else

                Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)

                myWebRequest.Method = "GET"

                Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)

                Dim b As Boolean = myWebRequest.AllowAutoRedirect

                MessageBox.Show(b.ToString())

                myWebRequest.Abort()

                myWebResponse.Close()

            End If

        Catch ex As Exception

            MessageBox.Show("invalid entry")

        End Try

    End Sub

This simple code tells that request should follow auto redirect or not.

Allow Write Stream Buffering:

If you want to know that for buffering data has sent to the internet resource or not. For this purpose we have a property of HttpWebRequest class named AllowWriteStreamBuffering. This property takes and returns a Boolean value.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_writestream_Click(object sender, EventArgs e)

        {

            try

            {

                url = txt_url.Text;

                if (url == string.Empty)

                {

                    MessageBox.Show("Enter valid url");

                }

                else

                {

                    HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

                    myWebRequest.Method = "GET";

                    HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

                    bool b = myWebRequest.AllowWriteStreamBuffering;

                    MessageBox.Show(b.ToString());

                    myWebRequest.Abort();

                    myWebResponse.Close();

                }

            }

            catch (Exception ex) { MessageBox.Show("invalid entry"); }

        }

VB

Private Sub btn_writestream_Click(ByVal sender As Object, ByVal e As EventArgs)

        Try

            url = txt_url.Text

            If url = String.Empty Then

                MessageBox.Show("Enter valid url")

            Else

                Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)

                myWebRequest.Method = "GET"

                Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)

                Dim b As Boolean = myWebRequest.AllowWriteStreamBuffering

                MessageBox.Show(b.ToString())

                myWebRequest.Abort()

                myWebResponse.Close()

            End If

        Catch ex As Exception

            MessageBox.Show("invalid entry")

        End Try

    End Sub

This simple code tells that to buffer, data sent to the internet resource or not.

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP APPLICATION";

        }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP APPLICATION"

    End Sub

 

This simple article tells how we can get that server allow auto redirect, allow write stream buffering  and how we can get  connection http header value and connection  group name using HttpWebRequest class C#.net – vb.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get html source of web page using HttpWebRequest class C#.net – vb.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net