URLConnection.openConnection()和URLConnection.connect()之间的区别? [英] Difference between URLConnection.openConnection() and URLConnection.connect()?

查看:323
本文介绍了URLConnection.openConnection()和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 at connection.connect();?

  • How can I set URL in the connection Object and use it with connection.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆