*urlconnection is an abstract class that has two direct subclasses, namely HttpURLConnection and jarurlconnection. Another important class is the URL, which usually URLs can generate a URL instance to a specific address by passing it to a constructor with a string parameter.
The *url.openconnection () method returns is definitely one of these two subclasses, which is a manifestation of Java polymorphism
* retrace ... In Eclipse, press F3
1, find the OpenConnection () method.
2, locate the handler instance in the URL. Note: Handler is an abstract class urlstreamhandler a defined non-instantiated class.
3, handler = (URLStreamHandler) cls.newinstance ();.
①cl for System ClassLoader
5, getpropertyaction source code is not found, but guess Clsname points to an API that should at least overwrite the
①, URLConnection's Connect method
②, URLStreamHandler OpenConnection method
Note: Handlers stores the collection for handler, Factory is a custom handler. (See this section, can be discussed again)
* You can convert URLConnection to httpurlconnection directly, so you can put Urlconnection.setdooutput (true) Written as Httpurlconnection.setrequestmethod ("POST"), which in fact calls the former. If you have to use URLConnection's input stream, you must perform setdooutput (true)
*urlconnection.getinputstream () invokes the Urlconnection.connect () function.
URLConnection in Java