java.net.UrlConnection类的使用
来源:互联网 发布:mac系统剪切 编辑:程序博客网 时间:2024/06/10 01:17
URLConnection类是一个抽象,是实现应用程序和URL之间通信连接的所有类的超类,该类的实例可以用来读写URL所指的资源。在创建了URL对象之后,可以使用该URL对象的openConnection方法来创建URLConnection对象,之后就可以使用下面的方法完成各种各样的操作。
- abstract public void connect() throws IOException
打开与URL所指定资源的一个通信连接,如果调用该方法时连接已经打开,则忽略该调用。 - public URL getURL()
得到URLConnection对象的URL域。 - public int getContentLength()
得到content-type头域的值。 - public String getContentEncoding()
得到content-encoding头域的值。 - public long getDate()
得到date头域的值。 - public long getLastModified()
得到last-modified头域的值。 - public String getHeaderField(String name)
得到指定头域的名称。 - public Object getContent() throws IOException
得到URL连接的内容。该方法会先调用getContentType方法得到对象的内容类型,再做相应的处理。 - public InputStream getInputStream() throws IOException
- public OutputStream getOutputStream()throws IOException
得到URLConnection的输入或输出流。 - public void setDoInput(Boolean doinput)
设置URLConnection对象的doInput域的值。一个URL连接可以用于输入和(或)输出,如果准备将该URLConnection用于读取,可以设置DoInput标志为true。默认即为true。 - public Boolean getDoInput()
得到DoInput标志的值。 - public void setDoOutput(Boolean dooutput) 如果想通过URLConnection像服务端写东西,则设置为true,默认为false
- public Boolean getDoOutput()
设置或得到doOutput标志的值。 - public void setAllowUserInteracion(Boolean allowuserinteraction)
- public Boolean getAllowUserInteraction()
设置或得到allowUserInteraction域的值。 - public void setUseCaches(Boolean usecaches)
- public Boolean getUseCaches()
设置或得到useCaches域的值。 - public void setIfModifiedSince(long ifmodifiedsince)
- public long getIfModifiedSince()
设置或得到ifModifiedSince域的值。 - public void setRequestProperty(String key,String value)
- public String getRequestProperty(String key)
设置或得到普通的请求属性的值。Key为请求的关键字,例如:“accept”,value为与key相对应的值。
如果需要使用setDoOutput和setUseCaches等方法设置各种选项,必须是在URLConnection对象创建之后和连接之前。
- 通过在 URL 上调用
openConnection
方法创建连接对象。 - 处理设置参数和一般请求属性。如setDoPutput
- 使用
connect
方法建立到远程对象的实际连接。 - 远程对象变为可用。远程对象的头字段和内容变为可访问。亦可以向远程对象写入东西了。
使用以下方法修改设置参数:
setAllowUserInteraction
setDoInput
setDoOutput
setIfModifiedSince
setUseCaches
- java.net.UrlConnection类的使用
- java.net.UrlConnection类的使用
- java.net.UrlConnection类的使用
- java.net.UrlConnection类的使用
- Java网络连接-URLConnection类的使用
- java.net.URLConnection类_java模拟浏览器
- java.net.URLConnection翻译
- 关于java.net.URLConnection
- java.net.URLConnection
- java.net.URLConnection详解
- java中的URLConnection和HttpURLConnection的使用
- Java使用URLConnection类访问网络资源
- 如何使用 java.net.URLConnection 处理 HTTP 请求?
- JAVA代码java.net.URLConnection发送HTTP请求的方法
- java.net包下的URLConnection的用法
- 通过java.net.URLConnection发送HTTP请求的方法
- 通过java.net.URLConnection发送HTTP请求的方法
- Java.net.URLConnection和Apache HTTPClient的主要区别对比
- 函数式编程另类指南 (zz)
- Enemies and Combat: How to Create a Tile Based Game with Cocos2D Part 3
- lib 与 obj 文件的关系
- string的size
- 如何从硬盘驱动器检索已删除的历史记录
- java.net.UrlConnection类的使用
- LogicJava---Lesson4
- 给DataGridView添加右键菜单
- SELECT 语句完整的句法
- extern用法
- 安装 php-rabbit: RabbitMQ 的 PHP 扩展
- iPad2已经发布,目前没有评论
- Eclipse下建立junit测试
- 常见排序算法的稳定性