Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between WebRequest.Create and WebRequest.CreateHttp

Tags:

c#

webrequest

I am looking at the documentations between WebRequest.Create and WebRequest.CreateHttp to decide which I should use in my application. I do not see anything different between these two methods except WebRequest.Create returns a WebRequest and WebRequest.CreateHttp returns HttpWebRequest.

Are these two methods essentially the same except for the return value? Or do they each do something different internally?

like image 728
John Odom Avatar asked Oct 23 '25 11:10

John Odom


1 Answers

WebRequest.Create will return a WebRequest-derived request, based on the URL you use. If,for example, you use an FTP URL, the result will be a FileWebRequest. CreateHttp on the other hand creates an HttpWebRequest explicitly.

CreateHttp was added in .Net 4.0 while Create itself exists since 2.0.

Both methods will create an HttpWebRequest so they can be used interchangeably.

like image 62
Panagiotis Kanavos Avatar answered Oct 26 '25 03:10

Panagiotis Kanavos