📄 urlconnection.html
字号:
<!-- ========= CONSTRUCTOR DETAIL ======== --><A NAME="constructor_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Constructor Detail</B></FONT></TD></TR></TABLE><A NAME="URLConnection(java.net.URL)"><!-- --></A><H3>URLConnection</H3><PRE>protected <B>URLConnection</B>(<A HREF="../../java/net/URL.html">URL</A> url)</PRE><DL><DD>Constructs a URL connection to the specified URL. A connection to the object referenced by the URL is not created.<DD><DL><DT><B>Parameters:</B><DD><CODE>url</CODE> - the specified URL.</DL></DD></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="getFileNameMap()"><!-- --></A><H3>getFileNameMap</H3><PRE>public static <A HREF="../../java/net/FileNameMap.html">FileNameMap</A> <B>getFileNameMap</B>()</PRE><DL><DD>Loads filename map (a mimetable) from a data file. It will first try to load the user-specific table, defined by "content.types.user.table" property. If that fails, it tries to load the default built-in table at lib/content-types.properties under java home.<DD><DL><DT><B>Returns:</B><DD>the FileNameMap<DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#setFileNameMap(java.net.FileNameMap)"><CODE>setFileNameMap(java.net.FileNameMap)</CODE></A></DL></DD></DL><HR><A NAME="setFileNameMap(java.net.FileNameMap)"><!-- --></A><H3>setFileNameMap</H3><PRE>public static void <B>setFileNameMap</B>(<A HREF="../../java/net/FileNameMap.html">FileNameMap</A> map)</PRE><DL><DD>Sets the FileNameMap. <p> If there is a security manager, this method first calls the security manager's <code>checkSetFactory</code> method to ensure the operation is allowed. This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>map</CODE> - the FileNameMap to be set<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkSetFactory</code> method doesn't allow the operation.<DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkSetFactory()"><CODE>SecurityManager.checkSetFactory()</CODE></A>, <A HREF="../../java/net/URLConnection.html#getFileNameMap()"><CODE>getFileNameMap()</CODE></A></DL></DD></DL><HR><A NAME="connect()"><!-- --></A><H3>connect</H3><PRE>public abstract void <B>connect</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Opens a communications link to the resource referenced by this URL, if such a connection has not already been established. <p> If the <code>connect</code> method is called when the connection has already been opened (indicated by the <code>connected</code> field having the value <code>true</code>), the call is ignored. <p> 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.<DD><DL><DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs while opening the connection.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#connected"><CODE>connected</CODE></A></DL></DD></DL><HR><A NAME="getURL()"><!-- --></A><H3>getURL</H3><PRE>public <A HREF="../../java/net/URL.html">URL</A> <B>getURL</B>()</PRE><DL><DD>Returns the value of this <code>URLConnection</code>'s <code>URL</code> field.<DD><DL><DT><B>Returns:</B><DD>the value of this <code>URLConnection</code>'s <code>URL</code> field.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#url"><CODE>url</CODE></A></DL></DD></DL><HR><A NAME="getContentLength()"><!-- --></A><H3>getContentLength</H3><PRE>public int <B>getContentLength</B>()</PRE><DL><DD>Returns the value of the <code>content-length</code> header field.<DD><DL><DT><B>Returns:</B><DD>the content length of the resource that this connection's URL references, or <code>-1</code> if the content length is not known.</DL></DD></DL><HR><A NAME="getContentType()"><!-- --></A><H3>getContentType</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getContentType</B>()</PRE><DL><DD>Returns the value of the <code>content-type</code> header field.<DD><DL><DT><B>Returns:</B><DD>the content type of the resource that the URL references, or <code>null</code> if not known.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#getHeaderField(java.lang.String)"><CODE>getHeaderField(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="getContentEncoding()"><!-- --></A><H3>getContentEncoding</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getContentEncoding</B>()</PRE><DL><DD>Returns the value of the <code>content-encoding</code> header field.<DD><DL><DT><B>Returns:</B><DD>the content encoding of the resource that the URL references, or <code>null</code> if not known.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#getHeaderField(java.lang.String)"><CODE>getHeaderField(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="getExpiration()"><!-- --></A><H3>getExpiration</H3><PRE>public long <B>getExpiration</B>()</PRE><DL><DD>Returns the value of the <code>expires</code> header field.<DD><DL><DT><B>Returns:</B><DD>the expiration date of the resource that this URL references, or 0 if not known. The value is the number of milliseconds since January 1, 1970 GMT.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#getHeaderField(java.lang.String)"><CODE>getHeaderField(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="getDate()"><!-- --></A><H3>getDate</H3><PRE>public long <B>getDate</B>()</PRE><DL><DD>Returns the value of the <code>date</code> header field.<DD><DL><DT><B>Returns:</B><DD>the sending date of the resource that the URL references, or <code>0</code> if not known. The value returned is the number of milliseconds since January 1, 1970 GMT.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#getHeaderField(java.lang.String)"><CODE>getHeaderField(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="getLastModified()"><!-- --></A><H3>getLastModified</H3><PRE>public long <B>getLastModified</B>()</PRE><DL><DD>Returns the value of the <code>last-modified</code> header field. The result is the number of milliseconds since January 1, 1970 GMT.<DD><DL><DT><B>Returns:</B><DD>the date the resource referenced by this <code>URLConnection</code> was last modified, or 0 if not known.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#getHeaderField(java.lang.String)"><CODE>getHeaderField(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="getHeaderField(java.lang.String)"><!-- --></A><H3>getHeaderField</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getHeaderField</B>(<A HREF="../../java/lang/String.html">String</A> name)</PRE><DL><DD>Returns the name of the specified header field.<DD><DL><DT><B>Parameters:</B><DD><CODE>name</CODE> - the name of a header field.<DT><B>Returns:</B><DD>the value of the named header field, or <code>null</code> if there is no such field in the header.</DL></DD></DL><HR><A NAME="getHeaderFieldInt(java.lang.String, int)"><!-- --></A><H3>getHeaderFieldInt</H3><PRE>public int <B>getHeaderFieldInt</B>(<A HREF="../../java/lang/String.html">String</A> name, int Default)</PRE><DL><DD>Returns the value of the named field parsed as a number. <p> This form of <code>getHeaderField</code> exists because some connection types (e.g., <code>http-ng</code>) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.<DD><DL><DT><B>Parameters:</B><DD><CODE>name</CODE> - the name of the header field.<DD><CODE>Default</CODE> - the default value.<DT><B>Returns:</B><DD>the value of the named field, parsed as an integer. The <code>Default</code> value is returned if the field is missing or malformed.</DL></DD></DL><HR><A NAME="getHeaderFieldDate(java.lang.String, long)"><!-- --></A><H3>getHeaderFieldDate</H3><PRE>public long <B>getHeaderFieldDate</B>(<A HREF="../../java/lang/String.html">String</A> name, long Default)</PRE><DL><DD>Returns the value of the named field parsed as date. The result is the number of milliseconds since January 1, 1970 GMT represented by the named field. <p> This form of <code>getHeaderField</code> exists because some connection types (e.g., <code>http-ng</code>) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.<DD><DL><DT><B>Parameters:</B><DD><CODE>name</CODE> - the name of the header field.<DD><CODE>Default</CODE> - a default value.<DT><B>Returns:</B><DD>the value of the field, parsed as a date. The value of the <code>Default</code> argument is returned if the field is missing or malformed.</DL></DD></DL><HR><A NAME="getHeaderFieldKey(int)"><!-- --></A><H3>getHeaderFieldKey</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getHeaderFieldKey</B>(int n)</PRE><DL><DD>Returns the key for the <code>n</code><sup>th</sup> header field.<DD><DL><DT><B>Parameters:</B><DD><CODE>n</CODE> - an index.<DT><B>Returns:</B><DD>the key for the <code>n</code><sup>th</sup> header field, or <code>null</code> if there are fewer than <code>n</code> fields.</DL></DD></DL><HR><A NAME="getHeaderField(int)"><!-- --></A><H3>getHeaderField</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getHeaderField</B>(int n)</PRE><DL><DD>Returns the value for the <code>n</code><sup>th</sup> header field. It returns <code>null</code> if there are fewer than <code>n</code> fields. <p> This method can be used in conjunction with the <code>getHeaderFieldKey</code> method to iterate through all the headers in the message.<DD><DL><DT><B>Parameters:</B><DD><CODE>n</CODE> - an index.<DT><B>Returns:</B><DD>the value of the <code>n</code><sup>th</sup> header field.<DT><B>See Also: </B><DD><A HREF="../../java/net/URLConnection.html#getHeaderFieldKey(int)"><CODE>getHeaderFieldKey(int)</CODE></A></DL></DD></DL><HR><A NAME="getContent()"><!-- --></A><H3>getContent</H3><PRE>public <A HREF="../../java/lang/Object.html">Object</A> <B>getContent</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Retrieves the contents of this URL connection. <p> This method first determines the content type of the object by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -