Você está na página 1de 13

Inside of HttpWebRequest

WebRequest
9th April 2013 Midhat Zehra Department Of Computer Science University Of Karachi

Creating Internet Requests


HttpWebRequest class, which is derived from WebRequest(abstract class), to handle HTTP and HTTPS requests The HttpWebResponse object handles the responses from HTTP and HTTPS request. To access the HTTP-specific properties of the HttpWebResponse object, you need to cast WebResponse objects to the HttpWebResponse type

How to: Request Data Using the WebRequest Class


To request data from a host server

Step 1:
Create a WebRequest instance by calling Create with the URI of the resource.[2]

Step 2
Set any property values that you need in the WebRequest. For example, to enable authentication, set the Credentials property to an instance of the NetworkCredential class[2]

To set protocol-specific properties, cast the WebRequest to the protocol-specific type[2]

Step 3
To send the request to the server, call GetResponse. The actual type of the returned WebResponse object is determined by the scheme of the requested URI. [2]

Step 4
The following code example shows how to display the status information sent with a response.

Step 5
To get the stream containing response data sent by the server, use the GetResponseStream method of the WebResponse.

WebResponse.Close calls Stream.Close when closing the response

How to: Request Data Using the WebRequest Class

How to: Send Data Using the WebRequest Class

Making Asynchronous Requests


What is the difference between asynchronous and synchronous request? In a word, a program does not wait for response after requesting an asynchronous call whereas synchronous does so.
function check() { var a=0; a = getStatus(getstatus.php?id=5); if(a==1) { alert(active); } else { alert(not active); } }

Callback function is that function which is triggered when the request completes to get the response

Dictionary
Static Method: have no instances. They are called with the type name, not an instance identifier.[3] Abstract Classes : is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies,

References
[1] http://msdn.microsoft.com/enus/library/69b8ttkf.aspx [2]http://msdn.microsoft.com/enus/library/456dfw4f.aspx [3]http://www.dotnetperls.com/static-method [4]http://www.dotnetfunda.com/interview/ex am90-what-is-abstract-class.aspx

Thanks

Você também pode gostar