📄 urlconnection.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:35:36 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class URLConnection</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/URLConnection.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/net/URLClassLoader.html"><B>PREV CLASS</B></A> <A HREF="../../java/net/URLDecoder.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="URLConnection.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.net</FONT><BR>Class URLConnection</H2><PRE><A HREF="../../java/lang/Object.html">java.lang.Object</A> | +--<B>java.net.URLConnection</B></PRE><DL><DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../java/net/HttpURLConnection.html">HttpURLConnection</A>, <A HREF="../../java/net/JarURLConnection.html">JarURLConnection</A></DD></DL><HR><DL><DT>public abstract class <B>URLConnection</B><DT>extends <A HREF="../../java/lang/Object.html">Object</A></DL><P>The abstract class <code>URLConnection</code> 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: <p> <center><table border=2> <tr><th><code>openConnection()</code></th> <th><code>connect()</code></th></tr> <tr><td>Manipulate parameters that affect the connection to the remote resource.</td> <td>Interact with the resource; query header fields and contents.</td></tr> </table> ----------------------------> <br>time</center> <ol> <li>The connection object is created by invoking the <code>openConnection</code> method on a URL. <li>The setup parameters and general request properties are manipulated. <li>The actual connection to the remote object is made, using the <code>connect</code> method. <li>The remote object becomes available. The header fields and the contents of the remote object can be accessed. </ol> <p> The setup parameters are modified using the following methods: <ul> <li><code>setAllowUserInteraction</code> <li><code>setDoInput</code> <li><code>setDoOutput</code> <li><code>setIfModifiedSince</code> <li><code>setUseCaches</code> </ul> <p> and the general request properties are modified using the method: <ul> <li><code>setRequestProperty</code> </ul> <p> Default values for the <code>AllowUserInteraction</code> and <code>UseCaches</code> parameters can be set using the methods <code>setDefaultAllowUserInteraction</code> and <code>setDefaultUseCaches</code>. <p> Each of the above <code>set</code> methods has a corresponding <code>get</code> 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. <p> The following methods are used to access the header fields and the contents after the connection is made to the remote object: <ul> <li><code>getContent</code> <li><code>getHeaderField</code> <li><code>getInputStream</code> <li><code>getOutputStream</code> </ul> <p> Certain header fields are accessed frequently. The methods: <ul> <li><code>getContentEncoding</code> <li><code>getContentLength</code> <li><code>getContentType</code> <li><code>getDate</code> <li><code>getExpiration</code> <li><code>getLastModifed</code> </ul> <p> provide convenient access to these fields. The <code>getContentType</code> method is used by the <code>getContent</code> method to determine the type of the remote object; subclasses may find it convenient to override the <code>getContentType</code> method. <p> 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: <code>getInputStream</code> and <code>getObject</code>, which are mirrored in the <code>URL</code> class by convenience methods. <p> More information on the request properties and header fields of an <code>http</code> connection can be found at: <blockquote><pre> <a href="http://www.ietf.org/rfc/rfc2068.txt">http://www.ietf.org/rfc/rfc2068.txt</a> </pre></blockquote> Note about <code>fileNameMap</code>: In versions prior to JDK 1.1.6, field <code>fileNameMap</code> of <code>URLConnection</code> was public. In JDK 1.1.6 and later, <code>fileNameMap</code> is private; accessor and mutator methods <A HREF="../../java/net/URLConnection.html#getFileNameMap()"><CODE>getFileNameMap</CODE></A> and <A HREF="../../java/net/URLConnection.html#setFileNameMap(java.net.FileNameMap)"><CODE>setFileNameMap</CODE></A> are added to access it. This change is also described on the <a href= "http://java.sun.com/products/jdk/1.2/compatibility.html#incompatibilities1.2"> Compatibility</a> page.<P><DL><DT><B>Since: </B><DD>JDK1.0</DD><DT><B>See Also: </B><DD><A HREF="../../java/net/URL.html#openConnection()"><CODE>URL.openConnection()</CODE></A>, <A HREF="../../java/net/URLConnection.html#connect()"><CODE>connect()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getContent()"><CODE>getContent()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getContentEncoding()"><CODE>getContentEncoding()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getContentLength()"><CODE>getContentLength()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getContentType()"><CODE>getContentType()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getDate()"><CODE>getDate()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getExpiration()"><CODE>getExpiration()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getHeaderField(int)"><CODE>getHeaderField(int)</CODE></A>, <A HREF="../../java/net/URLConnection.html#getHeaderField(java.lang.String)"><CODE>getHeaderField(java.lang.String)</CODE></A>, <A HREF="../../java/net/URLConnection.html#getInputStream()"><CODE>getInputStream()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getLastModified()"><CODE>getLastModified()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getOutputStream()"><CODE>getOutputStream()</CODE></A>, <A HREF="../../java/net/URLConnection.html#setAllowUserInteraction(boolean)"><CODE>setAllowUserInteraction(boolean)</CODE></A>, <A HREF="../../java/net/URLConnection.html#setDefaultUseCaches(boolean)"><CODE>setDefaultUseCaches(boolean)</CODE></A>, <A HREF="../../java/net/URLConnection.html#setDoInput(boolean)"><CODE>setDoInput(boolean)</CODE></A>, <A HREF="../../java/net/URLConnection.html#setDoOutput(boolean)"><CODE>setDoOutput(boolean)</CODE></A>, <A HREF="../../java/net/URLConnection.html#setIfModifiedSince(long)"><CODE>setIfModifiedSince(long)</CODE></A>, <A HREF="../../java/net/URLConnection.html#setRequestProperty(java.lang.String, java.lang.String)"><CODE>setRequestProperty(java.lang.String, java.lang.String)</CODE></A>, <A HREF="../../java/net/URLConnection.html#setUseCaches(boolean)"><CODE>setUseCaches(boolean)</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#allowUserInteraction">allowUserInteraction</A></B></CODE><BR> If <code>true</code>, this <code>URL</code> is being examined in a context in which it makes sense to allow user interactions such as popping up an authentication dialog.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#connected">connected</A></B></CODE><BR> If <code>false</code>, this connection object has not created a communications link to the specified URL.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#doInput">doInput</A></B></CODE><BR> This variable is set by the <code>setDoInput</code> method.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#doOutput">doOutput</A></B></CODE><BR> This variable is set by the <code>setDoOutput</code> method.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected long</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#ifModifiedSince">ifModifiedSince</A></B></CODE><BR> Some protocols support skipping the fetching of the object unless the object has been modified more recently than a certain time.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../../java/net/URL.html">URL</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#url">url</A></B></CODE><BR> The URL represents the remote object on the World Wide Web to which this connection is opened.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/URLConnection.html#useCaches">useCaches</A></B></CODE><BR> If <code>true</code>, the protocol is allowed to use caching whenever it can.</TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -