Difference between URLConnection, HttpURLConnection and HttpsURLConnection

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 10:55:29

问题


What is the difference between URLConnection, HttpURLConnection and HttpsURLConnection (with SSL). Under what conditions, which one should I use?


回答1:


URLConnection is the base class.

HttpURLConnection is a derived class which you can use when you need the extra API and you are dealing with HTTP or HTTPS only.

HttpsURLConnection is a 'more derived' class which you can use when you need the 'more extra' API and you are dealing with HTTPS only.

All three of them are abstract, and implemented by specific classes you aren't privy to.




回答2:


URLConnection is an abstract class so, you could never instantiate an object of that type.

HttpURLConnection extends URLConnection and provides fields and methods specific to an HTTP URL, such as, HTTP_CLIENT_TIMEOUT or setRequestMethod.

HttpsURLConnection extends HttpURLConnection and provides fields and methods specific to an HTTPS URL.



来源:https://stackoverflow.com/questions/3920419/difference-between-urlconnection-httpurlconnection-and-httpsurlconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!