You are on page 1of 3

request and response objectsRequest, Response Objects Request and Response objects represent information coming into the

Web server fr om the browser and information going out from the server to the browser. The Req uest object is called the input object and the Response object is called the out put object. Response Object As mentioned above, the Response object represents a valid HTTP response that wa s received from the server. The response header properties are read-only. Notabl e properties of the object are as follows: Body: Gets the body of the HTTP response. Only the portion of the body stored in the response buffer is returned BytesRecv: Gets the number of bytes the client received in the response BytesSent: Gets the number of bytes send in the HTTP request CodePage: Gets or sets the code page used for setting the body of the HTTP respo nse ContentLength: Gets the size, in bytes, of the response body Headers: Gets a collection of headers in the response HeaderSize: Gets the combined size, in bytes, of all the response headers HTTPVersion: Gets the HTTP version used by the server for this response Path: Gets the path that was requested Port: Gets the server port used for the request ResultCode: Gets the server's response status code Server: Gets the name of the server that sent the response TTFB: Gets the number of milliseconds that have passed before the first byte of the response was received TTLB: Gets the number of millise conds that passed before the last byte of the response was received UseSSL: Checks whether the server and client used an SSL connection for the requ est and response Sample Code The following sample code assumes that you have a Button control and four RadioB uttoin controls with a common GroupName property on a Web Form. The user will be sent to a new Web Page if he makes a selection from one of the radio button's a nd hits the Submit button. You can view the live demo at the bottom of this page . Private Sub Page_Load(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles MyBase.Load Dim ccc As String = "Response Object" Response.Write(ccc) Response.Write("Using Response object") 'using the response object's write method to write some text End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles Button1.Click If RadioButton1.Checked = True Then Response.Redirect("http://www.google.com") 'using the response object's redirect method to redirect the user to another web page ElseIf RadioButton2.Checked = True Then Response.Redirect("http://www.amazon.com") ElseIf RadioButton3.Checked = True Then

Response.Redirect("http://www.yahoo.com") ElseIf RadioButton4.Checked = True Then Response.Redirect("http://www.startvbdotnet.com") End If End Sub

Request Object As mentioned above, the Request object represents an HTTP request before it has been sent to the server. Notable properties of this object are as follows: Body: Gets/Sets the HTTP request body CodePage: Gets/Sets the code page for the request body EncodeBody: Gets/Sets whether ACT automatically URL encodes the request body EncodeQueryAsUTF8: Gets/Sets whether ACT automatically UTF-8 encodes the request 's query string Headers: Gets the HTTP Headers collection object HTTPVersion: Gets/Sets the HTTP version Path: Gets/Sets the HTTP path ResponseBufferSize: Gets/Sets the size of the buffer used to store the response body Verb: Gets/Sets the HTTP method verb Sample Code Private Sub Page_Load(ByVal sender As System.Object,_ ByVal e As System.EventArgs) Handles MyBase.Load Dim s As String = Request.UserHostAddress() 'request's user's host address and writes using the response object's write meth od Response.Write(s) Dim a As String = Request.ApplicationPath() 'request's the application path Response.Write(a) Dim aa As String = Request.Browser.Browser 'request's the type of browser Response.Write(aa) Dim b As String = Request.CurrentExecutionFilePath 'request's the current execution path Response.Write(b) Dim c As String = Request.FilePath 'request's the path to the file that you are currently working with Response.Write(c) Dim cc As String = Request.HttpMethod 'gets the HttpMethod Response.Write(cc)

If Request.Browser.Browser = "IE" Then 'checks to see if the browser is IE and if true displays a message Response.Write("You are using IE") Else Response.Write("You are using some other browser") End If Response.Write("Your computer is/has the following" & Request.Useragent) 'displays the user information about his computer End Sub