Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the java.net.HttpURLConnection become sun.net.www.protocol.http.HttpURLConnection?

Tags:

java

I have a code like this:

HttpURLConnection connection = (HttpURLConnection) loginUrl.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");
connection.setRequestProperty("Connection", "keep-alive");
connection.setRequestProperty("Referer", "http://www.icourse163.org/member/logout.htm");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);

OutputStream out = connection.getOutputStream();

I the connection is a instance of HttpURLConnection, But when I debug the code. When the code runs to OutputStream out = connection.getOutputStream();.I saw that the getOutputStream() is the sun.net.www.protocol.http.HttpURLConnection's method. why?

like image 732
lxacoder Avatar asked Oct 22 '25 14:10

lxacoder


1 Answers

Because java.net.HttpURLConnection is an abstract class, and sun.net.www.protocol.http.HttpURLConnection is its implementation in the Oracle JRE.

like image 150
user207421 Avatar answered Oct 24 '25 06:10

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!