Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between HttpRequest, HttpWebRequest and WebRequest

Tags:

asp.net

I was wondering if somebody explain the difference for the listed classes

like image 867
user970742 Avatar asked Nov 21 '11 09:11

user970742


People also ask

What is the difference between HttpWebRequest and WebRequest?

WebRequest is an abstract class. The HttpWebRequest class allows you to programmatically make web requests to the HTTP server.

What is a WebRequest?

What is a Web Request? A web request is a communicative message that is transmitted between the client, or web browsers, to the servers. This request is essential in providing the user with the correct and preferred webpages that the server will then display on the user's interface.

Should I dispose HttpWebRequest?

HttpWebRequest does not implement IDisposable so it does not require disposing. just set the httprequest object to null once your done with it.

What is the difference between HttpClient and Web client?

In a nutshell, WebRequest—in its HTTP-specific implementation, HttpWebRequest—represents the original way to consume HTTP requests in . NET Framework. WebClient provides a simple but limited wrapper around HttpWebRequest. And HttpClient is the new and improved way of doing HTTP requests and posts, having arrived with .


1 Answers

They do different things.

WebRequest is the abstract base class for HttpWebRequest - you can't use it directly. It is the base class of other *Request classes (for FTP, File and other types of web requests). These classes are all used for getting resources (files) from the web.

There is also a WebClient class - probably the simplest to use of all the BCL classes designed to retrieve a resource from the Internet.

HttpRequest, on the other hand represents a request for a resource in an ASP.NET application - this is the server side of a Request.

The main difference is that HttpWebRequest is an HTTP client, and HttpRequest is server side to be used in an ASP.NET web application.

like image 70
Oded Avatar answered Sep 21 '22 01:09

Oded