简体   繁体   中英

Difference between WebRequest.Create and WebRequest.CreateHttp

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM