URLConnection.openConnection()和URLConnection.connect()之间的区别? [英] Difference between URLConnection.openConnection() and URLConnection.connect()?
问题描述
在code:
HttpURLConnection的连接=(HttpURLConnection类)createMerchURL.openConnection();
connection.setRequestMethod(PUT);
connection.addRequestProperty(姓名,值1);connection.connect();..
connection.disconnect();
-
在该连接越来越竟开?在
.. createMerchURL.openConnection();
?或者在connection.connect();
-
如何在
连接
对象设定网址和使用connection.connect()
?(因为我与.openConnection不太舒服()
)
最后,是两者之间有什么区别呢?
谢谢..
当连接越来越竟开?在..createMerchURL.openConnection(); ?或connection.connect();
块引用>后者。前者只是解析URL,认定该协议,并创建
HttpURLConnection类
对象。
我怎么可以在连接对象设定网址
块引用>您不能。
和与connection.connect使用()?
块引用>您不能。
(因为我有.openConnection不太舒服())
块引用>坏运气:获得舒适与它
。In the code:
HttpURLConnection connection = (HttpURLConnection)createMerchURL.openConnection(); connection.setRequestMethod("PUT"); connection.addRequestProperty("Name", "Value1"); connection.connect(); .. connection.disconnect();
When is the connection getting opened actually? At
..createMerchURL.openConnection();
? or atconnection.connect();
?How can I set URL in the
connection
Object and use it withconnection.connect()
?(as I am less comfortable with.openConnection()
)Finally, is there any difference between the two?
Thanks..
解决方案When is the connection getting opened actually? At ..createMerchURL.openConnection(); ? or at connection.connect();?
The latter. The former just parses the URL, finds the protocol, and creates the
HttpURLConnection
object.How can I set URL in the connection Object
You can't.
and use it with connection.connect()?
You can't.
(as I am less comfortable with .openConnection())
Bad luck: get comfy with it.
这篇关于URLConnection.openConnection()和URLConnection.connect()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!