- 浏览: 16589217 次
- 性别:
- 来自: 济南
最新评论
-
wu1236:
ef0793cd94337324b6fefc4c9474af5 ...
Android ApiDemos示例解析(87):Media->MediaPlayer -
77219634:
0127bf2236bee4dd1f632ce430f1af1 ...
本博客文章都为转载,没有任何版权! -
77219634:
0127bf2236bee4dd1f632ce430f1af1 ...
VPLEX - EMC的RAC -
77219634:
0127bf2236bee4dd1f632ce430f1af1 ...
qTip2 Show -
77219634:
0127bf2236bee4dd1f632ce430f1af1 ...
SecureCRT中文乱码、复制粘贴乱码解决办法(修改版)
<!-- -->
|
JavaTM2Platform Std.Ed. v1.4.2 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> All Classes <noscript></noscript> | ||||||||
SUMMARY:NESTED|FIELD|CONSTR|METHOD | DETAIL:FIELD|CONSTR|METHOD |
<!-- ======== START OF CLASS DATA ======== -->
java.net
Class URLConnection
java.lang.Object java.net.URLConnection
The abstract class URLConnection
is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. In general, creating a connection to a URL is a multistep process: 抽象类URLConnection是所有表示应用程序和URL之间通信链接的类的父类。该类的实例可以用来向URL表示的资源读取或写入。 通常创建一个URL连接是个多步骤进程:
Manipulate parameters that affect the connection to the remote resource. 操作影响远程资源连接的参数。 | Interact with the resource; query header fields and contents. 和资源交互,查询头字段和内容。 |
time
- The connection object is created by invoking the
openConnection
method on a URL. 通过调用URL的openConnection方法返回连接对象。 - The setup parameters and general request properties are manipulated. 配置参数和通用请求属性。
- The actual connection to the remote object is made, using the
connect
method. 使用connect方法进行与远程对象的实际连接。 - The remote object becomes available. The header fields and the contents of the remote object can be accessed. 远程对象成为可用。远程对象的头字段和内容可以被访问。
The setup parameters are modified using the following methods: 使用以下方法修改配置参数:
setAllowUserInteraction
setDoInput
setDoOutput
setIfModifiedSince
setUseCaches
and the general request properties are modified using the method: 使用该方法修改通用请求属性:
setRequestProperty
Default values for the AllowUserInteraction
and UseCaches
parameters can be set using the methods setDefaultAllowUserInteraction
and setDefaultUseCaches
. AllowUserInteraction和UseCaches参数的默认值可以使用setDefaultAllowUserInteraction和setDefaultUseCaches方法来设置。
Each of the above set
methods has a corresponding get
method to retrieve the value of the parameter or general request property. The specific parameters and general request properties that are applicable are protocol specific. 以上每一个set方法都有一个对应的get方法来获取参数或者通用请求属性的值。特定的参数和适当的通用请求属性是协议特有的。
The following methods are used to access the header fields and the contents after the connection is made to the remote object: 在与远程对象建立连接后使用以下方法访问头字段和内容:
getContent
getHeaderField
getInputStream
getOutputStream
Certain header fields are accessed frequently. The methods: 某些头字段经常被访问。它们是:
getContentEncoding
getContentLength
getContentType
getDate
getExpiration
getLastModifed
provide convenient access to these fields. The getContentType
method is used by the getContent
method to determine the type of the remote object; subclasses may find it convenient to override the getContentType
method. 提供这些字段的便捷访问。getContentType方法由getContent方法实用类确定远程对象的类型, 子类可以方便地覆盖getContentType方法。
In the common case, all of the pre-connection parameters and general request properties can be ignored: the pre-connection parameters and request properties default to sensible values. For most clients of this interface, there are only two interesting methods: getInputStream
and getContent
, which are mirrored in the URL
class by convenience methods. 通常情况下,所有预连接变量和通用请求属性可以被忽略:预连接变量和请求属性默认为敏感值。 对于大部分客户端接口,只有两个方法有意义:getInputStream和getContent, 这些便捷方法是对URL类中的映射。
More information on the request properties and header fields of an http
connection can be found at: 请求属性和http连接的头字段的更多信息可以参见:
Note abouthttp://www.ietf.org/rfc/rfc2068.txt
fileNameMap
: In versions prior to JDK 1.1.6, field fileNameMap
of URLConnection
was public. In JDK 1.1.6 and later, fileNameMap
is private; accessor and mutator methods getFileNameMap
and setFileNameMap
are added to access it. This change is also described on the Compatibility page. Calling the close() methods on the InputStream or OutputStream of an URLConnection after a request may free network resources associated with this instance, unless particular protocol specifications specify different behaviours for it. 注意fileNameMap:在JDK 1.1.6之前的版本,URLConnection的fileNameMap域是公开的。在JDK 1.1.6 以后,fileNameMap是私有的。加入了getFileNameMap和setFileNameMap方法来访问和设置。 这些变化在Compatibility页中也有描述。在请求之后调用close()方法关闭InputStream或OutputStream 可以释放和实例相关的网络资源,除非特定的协议规范具体说明了行为的不同。
URL.openConnection()
, connect()
, getContent()
, getContentEncoding()
, getContentLength()
, getContentType()
, getDate()
, getExpiration()
, getHeaderField(int)
, getHeaderField(java.lang.String)
, getInputStream()
, getLastModified()
, getOutputStream()
, setAllowUserInteraction(boolean)
, setDefaultUseCaches(boolean)
, setDoInput(boolean)
, setDoOutput(boolean)
, setIfModifiedSince(long)
, setRequestProperty(java.lang.String, java.lang.String)
, setUseCaches(boolean)
<!-- ======== NESTED CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- -->
Field Summary | |
protected boolean |
allowUserInteraction If true , this URL is being examined in a context in which it makes sense to allow user interactions such as popping up an authentication dialog. 如果为true,此URL将在一定的上下文环境中被检验,是否允许用户交互,比如弹出一个认证对话框。
|
protected boolean |
connected If false , this connection object has not created a communications link to the specified URL. 如果为false,此连接对象尚未创建到指定URL的通信链接。
|
protected boolean |
doInput This variable is set by the setDoInput method. 该变量由setDoInput方法设置。
|
protected boolean |
doOutput This variable is set by the setDoOutput method. 该变量由setDoOutput方法设置。
|
protected long |
ifModifiedSince Some protocols support skipping the fetching of the object unless the object has been modified more recently than a certain time. 一些协议支持忽略取回对象的操作,直到一定时间后对象被修改。 |
protected URL |
url The URL represents the remote object on the World Wide Web to which this connection is opened. URL表示连接被打开的www上的远程对象。 |
protected boolean |
useCaches If true , the protocol is allowed to use caching whenever it can. 如果为true,允许协议在可以使用缓存时使用缓存。
|
Constructor Summary | |
protected |
URLConnection(URLurl) Constructs a URL connection to the specified URL. 创建指定URL的URL连接。 |
Method Summary | |
void |
addRequestProperty(Stringkey, Stringvalue) Adds a general request property specified by a key-value pair. 增加指定键-值对的通用请求属性。 |
abstract void |
connect() Opens a communications link to the resource referenced by this URL, if such a connection has not already been established. 打开此URL指向的资源的通信连接,如果这个连接尚未建立。 |
boolean |
getAllowUserInteraction() Returns the value of the allowUserInteraction field for this object. 返回该对象allowUserInteraction域的值。
|
Object |
getContent() Retrieves the contents of this URL connection. 获取此URL连接的内容。 |
Object |
getContent(Class[]classes) Retrieves the contents of this URL connection. 获取此URL连接的内容。 |
String |
getContentEncoding() Returns the value of the content-encoding header field. 返回content-encoding头字段值。
|
int |
getContentLength() Returns the value of the content-length header field. 返回content-length头字段值。
|
String |
getContentType() Returns the value of the content-type header field. 返回content-type头字段值。
|
long |
getDate() Returns the value of the date header field. 返回date头字段值。
|
staticboolean |
getDefaultAllowUserInteraction() Returns the default value of the allowUserInteraction field. 返回allowUserInteraction域默认值。
|
staticString |
getDefaultRequestProperty(Stringkey) Deprecated.The instance specific getRequestProperty method should be used after an appropriate instance of URLConnection is obtained. 实例特定的getRequestProperty方法应当在获取适当的URLConnection实例后使用。 |
boolean |
getDefaultUseCaches() Returns the default value of a URLConnection 's useCaches flag. 返回URLConnection的useCaches标签的默认值。
|
boolean |
getDoInput() Returns the value of this URLConnection 's doInput flag. 返回URLConnection的doInput标签值。
|
boolean |
getDoOutput() Returns the value of this URLConnection 's doOutput flag. 返回URLConnection的doOutput标签值。
|
long |
getExpiration() Returns the value of the expires header field. 返回expires头字段值。
|
staticFileNameMap |
getFileNameMap() Loads filename map (a mimetable) from a data file. 从数据文件中加载文件名映射。 |
String |
getHeaderField(intn) Returns the value for the n th header field. 返回n th头字段值。
|
String |
getHeaderField(Stringname) Returns the value of the named header field. 返回指定名称的头字段值。 |
long |
getHeaderFieldDate(Stringname, longDefault) Returns the value of the named field parsed as date. 返回解析为时间的指定名称的字段值。 |
int |
getHeaderFieldInt(Stringname, intDefault) Returns the value of the named field parsed as a number. 返回解析为数字的指定名称的字段值。 |
String |
getHeaderFieldKey(intn) Returns the key for the n th header field. 返回n th头字段的键值。
|
Map |
getHeaderFields() Returns an unmodifiable Map of the header fields. 返回头字段的不可更改映射。 |
long |
getIfModifiedSince() Returns the value of this object's ifModifiedSince field. 返回对象ifModifiedSince域的值。
|
InputStream |
getInputStream() Returns an input stream that reads from this open connection. 返回从此打开连接读取的输入流。 |
long |
getLastModified() Returns the value of the last-modified header field. 返回last-modified头字段值。
|
OutputStream |
getOutputStream() Returns an output stream that writes to this connection. 返回向此连接写入的输出流。 |
Permission |
getPermission() Returns a permission object representing the permission necessary to make the connection represented by this object. 返回表示发起此对象表示的连接所需的许可的许可对象。 |
Map |
getRequestProperties() Returns an unmodifiable Map of general request properties for this connection. 返回此连接的通用请求属性的不可更改映射。 |
String |
getRequestProperty(Stringkey) Returns the value of the named general request property for this connection. 返回此连接的指定名称的通用请求属性的值。 |
URL |
getURL() Returns the value of this URLConnection 's URL field. 获得URLConnection的URL域值。
|
boolean |
getUseCaches() Returns the value of this URLConnection 's useCaches field. 获得URLConnection的useCaches域值。
|
staticString |
guessContentTypeFromName(Stringfname) Tries to determine the content type of an object, based on the specified "file" component of a URL. 根据URL的指定file组件,尝试确定对象的内容类型。 |
staticString |
guessContentTypeFromStream(InputStreamis) Tries to determine the type of an input stream based on the characters at the beginning of the input stream. 根据输入流的起始字符,尝试确定输入流的类型。 |
void |
setAllowUserInteraction(booleanallowuserinteraction) Set the value of the allowUserInteraction field of this URLConnection . 设置URLConnection的allowUserInteraction域值。
|
staticvoid |
setContentHandlerFactory(ContentHandlerFactoryfac) Sets the ContentHandlerFactory of an application. 设置应用的ContentHandlerFactory。
|
staticvoid |
setDefaultAllowUserInteraction(booleandefaultallowuserinteraction) Sets the default value of the allowUserInteraction field for all future URLConnection objects to the specified value. 用指定值设置以后URLConnection对象的allowUserInteraction域默认值。
|
staticvoid |
setDefaultRequestProperty(Stringkey, Stringvalue) Deprecated.The instance specific setRequestProperty method should be used after an appropriate instance of URLConnection is obtained. 实例特定的setRequestProperty方法应当在获取适当的URLConnection实例后使用。 |
void |
setDefaultUseCaches(booleandefaultusecaches) Sets the default value of the useCaches field to the specified value. 用指定值设置useCaches域默认值。
|
void |
setDoInput(booleandoinput) Sets the value of the doInput field for this URLConnection to the specified value. 用指定值设置此URLConnection的doInput域默认值。
|
void |
setDoOutput(booleandooutput) Sets the value of the doOutput field for this URLConnection to the specified value. 用指定值设置此URLConnection的doOutput域默认值。
|
staticvoid |
setFileNameMap(FileNameMapmap) Sets the FileNameMap. 设置FileNameMap。 |
void |
setIfModifiedSince(longifmodifiedsince) Sets the value of the ifModifiedSince field of this URLConnection to the specified value. 用指定值设置此URLConnection的ifModifiedSince域默认值。
|
void |
setRequestProperty(Stringkey, Stringvalue) Sets the general request property. 设置通用请求属性。 |
void |
setUseCaches(booleanusecaches) Sets the value of the useCaches field of this URLConnection to the specified value. 用指定值设置此URLConnection的useCaches域默认值。
|
String |
toString() Returns a String representation of this URL connection. 返回URL连接的String形式。
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
<!-- ============ FIELD DETAIL =========== --><!-- -->
Field Detail |
url
protected URL url
The value of this field can be accessed by the getURL
method. 该域值getURL方法可以访问。
The default value of this variable is the value of the URL argument in the URLConnection
constructor. 变量的默认值为URLConnection构造函数中的URL参数。
getURL()
, url
<!-- -->
doInput
protected boolean doInput
setDoInput
method. Its value is returned by the getDoInput
method. 该变量由setDoInput方法设置。值由getDoInput方法返回。 A URL connection can be used for input and/or output. Setting the doInput
flag to true
indicates that the application intends to read data from the URL connection. URL连接可以用于输入输出。将doInput标签设置为true表示应用将从URL连接中读取数据。
The default value of this field is true
. 该域的默认值为true。
getDoInput()
, setDoInput(boolean)
<!-- -->
doOutput
protected boolean doOutput
setDoOutput
method. Its value is returned by the getDoOutput
method. 该变量由setDoOutput方法设置。值由getDoOutput方法返回。 A URL connection can be used for input and/or output. Setting the doOutput
flag to true
indicates that the application intends to write data to the URL connection. URL连接可以用于输入输出。将doOutput标签设置为true表示应用将向URL连接中写入数据。
The default value of this field is false
. 该域的默认值为false。
getDoOutput()
, setDoOutput(boolean)
<!-- -->
allowUserInteraction
protected boolean allowUserInteraction
true
, this URL
is being examined in a context in which it makes sense to allow user interactions such as popping up an authentication dialog. If false
, then no user interaction is allowed. 如果为true,此URL将在一定的上下文环境中被检验,是否允许用户交互,比如弹出一个认证对话框。如果为 false,那么不允许用户交互。 The value of this field can be set by the setAllowUserInteraction
method. Its value is returned by the getAllowUserInteraction
method. Its default value is the value of the argument in the last invocation of the setDefaultAllowUserInteraction
method. 域的值由setAllowUserInteraction方法设置。值由getAllowUserInteraction方法返回。默认值 为上次调用setDefaultAllowUserInteraction方法的参数值。
getAllowUserInteraction()
, setAllowUserInteraction(boolean)
, setDefaultAllowUserInteraction(boolean)
<!-- -->
useCaches
protected boolean useCaches
true
, the protocol is allowed to use caching whenever it can. If false
, the protocol must always try to get a fresh copy of the object. 如果为true,允许协议在可以使用缓存时使用缓存。如果为false,协议应当总是尝试获取对象的最新拷贝。 This field is set by the setUseCaches
method. Its value is returned by the getUseCaches
method. 域由setUseCaches方法设置,值由getUseCaches方法返回。
Its default value is the value given in the last invocation of the setDefaultUseCaches
method. 默认值为上次调用setDefaultUseCaches方法的参数值。
setUseCaches(boolean)
, getUseCaches()
, setDefaultUseCaches(boolean)
<!-- -->
ifModifiedSince
protected long ifModifiedSince
A nonzero value gives a time as the number of milliseconds since January 1, 1970, GMT. The object is fetched only if it has been modified more recently than that time. 非0值给出的是从GMT1970年1月1日起的毫秒数。只有对象在超过这个时间后被修改了,才取回对象。
This variable is set by the setIfModifiedSince
method. Its value is returned by the getIfModifiedSince
method. 变量由setIfModifiedSince方法设置,值由getIfModifiedSince方法返回。
The default value of this field is 0
, indicating that the fetching must always occur. 域的默认值为0,表示取回始终发生。
getIfModifiedSince()
, setIfModifiedSince(long)
<!-- -->
connected
protected boolean connected
false
, this connection object has not created a communications link to the specified URL. If true
, the communications link has been established. 如果为false,此连接对象尚未创建到指定URL的通信链接。如果为true,通信链接已经建立。
Constructor Detail |
URLConnection
protected URLConnection(URLurl)
url
- the specified URL. 指定URL。Method Detail |
getFileNameMap
public static FileNameMap getFileNameMap()
setFileNameMap(java.net.FileNameMap)
<!-- -->
setFileNameMap
public static void setFileNameMap(FileNameMapmap)
If there is a security manager, this method first calls the security manager's checkSetFactory
method to ensure the operation is allowed. This could result in a SecurityException. 如果有安全管理器,方法首先调用安全管理器的checkSetFactory方法以确认操作允许。这可能导致SecurityException。
map
- the FileNameMap to be set 要设置的FileNameMap SecurityException
- if a security manager exists and its checkSetFactory
method doesn't allow the operation. 如果安全管理器存在,它的checkSetFactory方法不允许该操作时抛出。
SecurityManager.checkSetFactory()
, getFileNameMap()
<!-- -->
connect
public abstract void connect() throws IOException
If the connect
method is called when the connection has already been opened (indicated by the connected
field having the value true
), the call is ignored. 如果连接已经打开(connected域表示的值为true),调用被忽略。
URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary. URLConnection对象经过两个阶段:首先被创建,然后连接。创建后,且连接之前, 可以指定多种选项(比如doInput和UseCaches)。连接之后,试图设置它们则为一个错误。依赖于连接的操作,比如getContentLength,如果必需将默认为执行连接。
IOException
- if an I/O error occurs while opening the connection. 如果打开连接时发生I/O错误抛出。
connected
<!-- -->
getURL
public URL getURL()
URLConnection
's URL
field. 获得URLConnection的URL域值。
URLConnection
's URL
field. URLConnection的URL域值。 url
<!-- -->
getContentLength
public int getContentLength()
content-length
header field. 返回content-length头字段值。
-1
if the content length is not known. 连接URL引用资源的内容长度,如果内容长度未知返回-1。<!-- -->
getContentType
public String getContentType()
content-type
header field. 返回content-type头字段值。
null
if not known. 连接URL引用资源的内容类型,如果未知返回null。 getHeaderField(java.lang.String)
<!-- -->
getContentEncoding
public String getContentEncoding()
content-encoding
header field. 返回content-encoding头字段值。
null
if not known. 连接URL引用资源的内容编码,如果未知返回null。 getHeaderField(java.lang.String)
<!-- -->
getExpiration
public long getExpiration()
expires
header field. 返回expires头字段值。
getHeaderField(java.lang.String)
<!-- -->
getDate
public long getDate()
date
header field. 返回date头字段值。
0
if not known. The value returned is the number of milliseconds since January 1, 1970 GMT. URL引用资源的发送时间,如果未知返回0。返回值为从GMT1970年1月1日起的毫秒数。 getHeaderField(java.lang.String)
<!-- -->
getLastModified
public long getLastModified()
last-modified
header field. The result is the number of milliseconds since January 1, 1970 GMT. 返回last-modified头字段值。结果为从GMT1970年1月1日起的毫秒数。
URLConnection
was last modified, or 0 if not known. URLConnection引用资源上次被修改的时间,未知返回0。 getHeaderField(java.lang.String)
<!-- -->
getHeaderField
public String getHeaderField(Stringname)
If called on a connection that sets the same header multiple times with possibly different values, only the last value is returned. 如果使用不同值多次调用设置同样头的连接,则返回最新值。
name
- the name of a header field. 头字段的名称。 null
if there is no such field in the header. 指定名称的头字段值,如果没有那样的头字段返回null。<!-- -->
getHeaderFields
public Map getHeaderFields()
<!-- -->
getHeaderFieldInt
public int getHeaderFieldInt(Stringname, intDefault)
This form of getHeaderField
exists because some connection types (e.g., http-ng
) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing. 因为一些连接类型(比如http-ng)已预解析头,所以存在这种形式的getHeaderField。 该连接类型的类应当重载此方法并缩短解析的过程。
name
- the name of the header field. 头字段的名称。 Default
- the default value. 默认值。 Default
value is returned if the field is missing or malformed. 解析为数字的指定名称字段的值。如果字段缺失返回默认值。<!-- -->
getHeaderFieldDate
public long getHeaderFieldDate(Stringname, longDefault)
This form of getHeaderField
exists because some connection types (e.g., http-ng
) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing. 因为一些连接类型(比如http-ng)已预解析头,所以存在这种形式的getHeaderField。 该连接类型的类应当重载此方法并缩短解析的过程。
name
- the name of the header field. 头字段的名称。 Default
- a default value. 默认值。 Default
argument is returned if the field is missing or malformed. 解析为日期的字段值。如果字段缺失返回默认值。<!-- -->
getHeaderFieldKey
public String getHeaderFieldKey(intn)
n
th header field. It returns null
if there are fewer than n+1
fields. 返回n
th头字段的键值。如果字段数小于n+1,返回null。
n
- an index, where n>=0 索引,大于等于0 n
th header field, or null
if there are fewer than n+1
fields. n
th头字段的键值,如果字段数小于n+1,返回null。<!-- -->
getHeaderField
public String getHeaderField(intn)
n
th header field. It returns null
if there are fewer than n+1
fields. 返回n
th头字段的值。如果字段数小于n+1,返回null。 This method can be used in conjunction with the getHeaderFieldKey
method to iterate through all the headers in the message. 该方法可以和getHeaderFieldKey方法联合使用以遍历信息中的所有头。
n
- an index, where n>=0 索引,大于等于0 n
th header field or null
if there are fewer than n+1
fields n
th头字段的值,如果字段数小于n+1,返回null。 getHeaderFieldKey(int)
<!-- -->
getContent
public Object发表评论
相关推荐
有两种常见的方法:一是使用`java.net.URLConnection`类,二是通过Apache HttpClient库。这篇文章将对比这两种方法,探讨它们的优缺点以及适用场景。 `java.net.URLConnection`是Java标准库中的一个类,可以直接...
在Java编程中,`java.net.URLConnection`是用于与各种Internet协议进行通信的抽象类,而HTTP(超文本传输协议)是最常见的应用之一。本文将深入探讨如何利用URLConnection类发送HTTP请求,理解其工作原理,并提供...
`java.net.URLConnection`则是`URL`的子接口,它提供了与资源进行交互的方法,如打开连接、读取数据、设置请求头等。在“java.net.URL测试代码”的场景中,我们通常会用到这两个类来实现网络编程中的跨域请求,并...
`java.net.URLConnection`是Java标准库提供的一种基础网络连接类,可以用来处理各种类型的网络连接,包括HTTP。以下是如何利用`java.net.URLConnection`发送HTTP请求的详细步骤: 1. **创建URL对象**: 首先,你...
本文将详细介绍如何使用`java.net.URLConnection`来实现这一功能。`URLConnection`是Java标准库中的一个核心类,它允许我们与各种协议(包括HTTP)的URL进行交互。 一、Java原生API发送HTTP请求 1. **创建URL对象*...
5. **`Socket`和`URLConnection`**:虽然它们本身不是`InputStream`的直接子类,但通过调用`getInputStream()`方法,可以从网络套接字或URL连接读取数据。 #### 总结 综上所述,`java.io.Reader`和`java.io....
java中用URLConnection类post方式提交表单是指在java应用程序中使用java.net.URLConnection类来实现POST方式的表单提交。POST方式是HTTP协议中的一种常见的请求方法,它允许客户端向服务器发送数据。下面是使用...
3. URLConnection.java:`java.net.URLConnection`是所有Java URL连接类的基类,负责建立到URL指定的资源的连接。你可以通过它发送请求、接收响应,进行读写操作。 4. Socket.java:`java.net.Socket`是TCP/IP网络...
3. **URL与URLConnection**:`java.net.URL`类用于表示统一资源定位符,`java.net.URLConnection`则用于打开和操作与URL关联的连接。它们简化了HTTP、FTP等协议的访问。 4. **NIO(非阻塞I/O)**:Java 1.4引入了`...
URL和URLConnection:Java提供了java.net.URL和java.net.URLConnection等类,用于访问URL指定的资源,如网页、文件等,并进行数据的读取和写入。 HTTP客户端:Java提供了java.net.HttpURLConnection等类,用于创建...
在Java中,我们可以使用`java.net.URL`类来创建一个表示URL的对象,然后使用`java.net.URLConnection`打开与该URL的连接。一旦连接建立,我们可以读取输入流并将其写入本地文件以保存图片。以下是一个简单的示例: ...
在Java中,你可以使用`java.net.URL`和`java.net.URLConnection`类来实现GET请求。 2.HttpPost调用: HttpPost方式在HTTP请求的正文中传递参数,如`name1=value1&name2=value2...`。返回的响应同样是一个无`...
`java.net.URLConnection`类则是用于打开和操作与URL关联的连接,可以实现HTTP、FTP等协议的访问。 四、多线程处理网络请求 在网络编程中,通常需要处理并发的客户端请求。Java的多线程机制(如Thread类和Runnable...
在Java中,我们可以使用`java.net.URL`和`java.net.URLConnection`类来实现GET请求。以下是一个简单的示例,展示了如何使用GET方法下载服务器上的图片: ```java import java.io.InputStream; import java.net.URL;...
import java.net.URLConnection; public class SimpleDownloader { public static void download(String urlStr, String targetFilePath) throws Exception { URL url = new URL(urlStr); URLConnection ...
import java.net.URLConnection; public class Test { public static void main(String[] args) { String st = "北京"; String str = catchPage("http://api.liqwei.com/weather/?city=+" + st + "+"); ...
java.net.URLConnection con=server.openConnection(); java.io.InputStream in=con.getInputStream(); int c; while((c=in.read())!=-1){ str+=((char)c); } str=new String(str.getBytes(&...
import java.net.URLConnection; public class ImageDownloader { public static void main(String[] args) throws Exception { String imageUrl = "http://example.com/image.jpg"; URL url = new URL(imageUrl...
在Java中,可以使用`java.net.URL`、`java.net.URLConnection`和`java.io.*`相关的类来实现HTTP请求和响应。对于更复杂的HTTP操作,如POST请求、Cookie管理等,可以利用Apache HttpClient或Java 7以后引入的`java...