Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / January 2006

Tip: Looking for answers? Try searching our database.

using WebRequest vs. HttpWebRequest?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 20 Jan 2006 16:20 GMT
Makng a webrequest, both work but what is the benefit of using one over the
other in this implemention?

HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(strUrl);
vs.
WebRequest req = WebRequest.Create(strUrl);
Martin Honnen - 21 Jan 2006 12:23 GMT
> Makng a webrequest, both work but what is the benefit of using one over the
> other in this implemention?
>
> HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(strUrl);
> vs.
> WebRequest req = WebRequest.Create(strUrl);

WebRequest is an anstract class which has a factory method Create that
depending on the URL passed in creates an instance of a concrete
subclass. Whether you need or want
  HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(strUrl);
instead of
  WebRequest req = WebRequest.Create(strUrl);
depends on your needs and on what kind of URLs you pass in. If you only
pass in HTTP: URLs then the former allows you to access the properties
and methods the subclass HttpWebRequest implements in addition to those
defined on the base class WebRequest. But if you passed in a FTP: URL
then the attempt to cast to HttpWebRequest would fail.
The latter is generic and won't fail on any of the types of supported
URLs but of course without casting to any subclass you can only access
the properties and methods the base class defines.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Javier G. Lozano - 21 Jan 2006 21:27 GMT
To add to Martin's comment, you also have access to more HTTP specific
properties such as Content Type, Cookies, etc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.