java HttpURLConnection connect()、getInputStream()、getContent()、HttpGet
我使用HttpURLConnection类,但我对一些方法感到困惑
假设HttpURLConnection对象名为“c”
删除c.connect()将导致连接成功,并将毫无问题地检索连接结果
c.getInputStream()和(InputStream)c.grtContent()的输出是相同的,那么它们之间的区别是什么
使用HttpGet将达到与HttpURLConnection相同的方法,那么这两种方法之间的区别是什么
在URLConnection上,HttpURLConnection的额外好处是什么
c=(HttpURLConnection)(URL)。openConnection(); c、 connect()//添加或删除会产生相同的结果,那么此方法的用途是什么 InputStream=c.getInputStream(); InputStream2=(InputStream)c.getContent(); //stream和stream2是相同的,那么getInputStream()和getContent()之间的区别是什么呢
//============================
HttpGet c=新的HttpGet(url); HttpResponse response=c.execute(httpGet) InputStream3=响应。getEntity()。getContent(); //此外,stream3与stream&;流程2;那么,HttpGet和&;HttpURLConnection
# 1 楼答案
来自Android文档:
例如,您可以从
HttpURLConnection
检索HTTP方法或HTTP状态代码,它们是特定于HTTP的而
URLConnection
类是:通常的用法是:
URL
对象url.openConnection()
获取URLConnection
。返回的对象可以强制转换为HttpURLConnection
connection.getInputStream()
方法获取InputStream
关闭连接((请参阅@EJP注释)disconnect()
方法)关于
connect()
方法,来自Oracle文档:HttpGet
和HttpURLConnection
之间的区别在于它们属于两个不同的库,但在功能上它们或多或少是相同的(现在HttpGet
已被弃用和删除,因此在标准Android API中找不到它)