📄 httpurlconnection.html
字号:
<DD>Constructor for the URLStreamHandler.<DD><DL><DT><B>Parameters:</B><DD><CODE>u</CODE> - the 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="setFollowRedirects(boolean)"><!-- --></A><H3>setFollowRedirects</H3><PRE>public static void <B>setFollowRedirects</B>(boolean set)</PRE><DL><DD>Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class. True by default. Applets cannot change this variable. <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>set</CODE> - a <code>boolean</code> indicating whether or not to follow HTTP redirects.<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>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkSetFactory()"><CODE>SecurityManager.checkSetFactory()</CODE></A>, <A HREF="../../java/net/HttpURLConnection.html#getFollowRedirects()"><CODE>getFollowRedirects()</CODE></A></DL></DD></DL><HR><A NAME="getFollowRedirects()"><!-- --></A><H3>getFollowRedirects</H3><PRE>public static boolean <B>getFollowRedirects</B>()</PRE><DL><DD>Returns a <code>boolean</code> indicating whether or not HTTP redirects (3xx) should be automatically followed.<DD><DL><DT><B>Returns:</B><DD><code>true</code> if HTTP redirects should be automatically followed, <tt>false</tt> if not.<DT><B>See Also: </B><DD><A HREF="../../java/net/HttpURLConnection.html#setFollowRedirects(boolean)"><CODE>setFollowRedirects(boolean)</CODE></A></DL></DD></DL><HR><A NAME="setInstanceFollowRedirects(boolean)"><!-- --></A><H3>setInstanceFollowRedirects</H3><PRE>public void <B>setInstanceFollowRedirects</B>(boolean followRedirects)</PRE><DL><DD>Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this <code>HttpURLConnection</code> instance. <p> The default value comes from followRedirects, which defaults to true.<DD><DL><DT><B>Parameters:</B><DD><CODE>followRedirects</CODE> - a <code>boolean</code> indicating whether or not to follow HTTP redirects.<DT><B>See Also: </B><DD><A HREF="../../java/net/HttpURLConnection.html#instanceFollowRedirects"><CODE>instanceFollowRedirects</CODE></A>, <A HREF="../../java/net/HttpURLConnection.html#getInstanceFollowRedirects()"><CODE>getInstanceFollowRedirects()</CODE></A></DL></DD></DL><HR><A NAME="getInstanceFollowRedirects()"><!-- --></A><H3>getInstanceFollowRedirects</H3><PRE>public boolean <B>getInstanceFollowRedirects</B>()</PRE><DL><DD>Returns the value of this <code>HttpURLConnection</code>'s <code>instanceFollowRedirects</code> field.<DD><DL><DT><B>Returns:</B><DD>the value of this <code>HttpURLConnection</code>'s <code>instanceFollowRedirects</code> field.<DT><B>See Also: </B><DD><A HREF="../../java/net/HttpURLConnection.html#instanceFollowRedirects"><CODE>instanceFollowRedirects</CODE></A>, <A HREF="../../java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)"><CODE>setInstanceFollowRedirects(boolean)</CODE></A></DL></DD></DL><HR><A NAME="setRequestMethod(java.lang.String)"><!-- --></A><H3>setRequestMethod</H3><PRE>public void <B>setRequestMethod</B>(<A HREF="../../java/lang/String.html">String</A> method) throws <A HREF="../../java/net/ProtocolException.html">ProtocolException</A></PRE><DL><DD>Set the method for the URL request, one of: <UL> <LI>GET <LI>POST <LI>HEAD <LI>OPTIONS <LI>PUT <LI>DELETE <LI>TRACE </UL> are legal, subject to protocol restrictions. The default method is GET.<DD><DL><DT><B>Parameters:</B><DD><CODE>method</CODE> - the HTTP method<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/ProtocolException.html">ProtocolException</A></CODE> - if the method cannot be reset or if the requested method isn't valid for HTTP.<DT><B>See Also: </B><DD><A HREF="../../java/net/HttpURLConnection.html#getRequestMethod()"><CODE>getRequestMethod()</CODE></A></DL></DD></DL><HR><A NAME="getRequestMethod()"><!-- --></A><H3>getRequestMethod</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getRequestMethod</B>()</PRE><DL><DD>Get the request method.<DD><DL><DT><B>Returns:</B><DD>the HTTP request method<DT><B>See Also: </B><DD><A HREF="../../java/net/HttpURLConnection.html#setRequestMethod(java.lang.String)"><CODE>setRequestMethod(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="getResponseCode()"><!-- --></A><H3>getResponseCode</H3><PRE>public int <B>getResponseCode</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Gets HTTP response status from responses like: <PRE> HTTP/1.0 200 OK HTTP/1.0 401 Unauthorized </PRE> Extracts the ints 200 and 401 respectively. Returns -1 if none can be discerned from the response (i.e., the response is not valid HTTP).<DD><DL><DT><B>Returns:</B><DD>the HTTP Status-Code<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an error occurred connecting to the server.</DL></DD></DL><HR><A NAME="getResponseMessage()"><!-- --></A><H3>getResponseMessage</H3><PRE>public <A HREF="../../java/lang/String.html">String</A> <B>getResponseMessage</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Gets the HTTP response message, if any, returned along with the response code from a server. From responses like: <PRE> HTTP/1.0 200 OK HTTP/1.0 404 Not Found </PRE> Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).<DD><DL><DT><B>Returns:</B><DD>the HTTP response message, or <code>null</code><DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an error occurred connecting to the server.</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><B>Description copied from class: <CODE><A HREF="../../java/net/URLConnection.html">URLConnection</A></CODE></B></DD><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>Overrides:</B><DD><CODE><A HREF="../../java/net/URLConnection.html#getHeaderFieldDate(java.lang.String, long)">getHeaderFieldDate</A></CODE> in class <CODE><A HREF="../../java/net/URLConnection.html">URLConnection</A></CODE></DL></DD><DD>Following copied from class: <CODE>java.net.URLConnection</CODE></DD><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="disconnect()"><!-- --></A><H3>disconnect</H3><PRE>public abstract void <B>disconnect</B>()</PRE><DL><DD>Indicates that other requests to the server are unlikely in the near future. Calling disconnect() should not imply that this HttpURLConnection instance can be reused for other requests.</DL><HR><A NAME="usingProxy()"><!-- --></A><H3>usingProxy</H3><PRE>public abstract boolean <B>usingProxy</B>()</PRE><DL><DD>Indicates if the connection is going through a proxy.<DD><DL><DT><B>Returns:</B><DD>a boolean indicating if the connection is using a proxy.</DL></DD></DL><HR><A NAME="getPermission()"><!-- --></A><H3>getPermission</H3><PRE>public <A HREF="../../java/security/Permission.html">Permission</A> <B>getPermission</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD><B>Description copied from class: <CODE><A HREF="../../java/net/URLConnection.html">URLConnection</A></CODE></B></DD><DD>Returns a permission object representing the permission necessary to make the connection represented by this object. This method returns null if no permission is required to make the connection. By default, this method returns <code>java.security.AllPermission</code>. Subclasses should override this method and return the permission that best represents the permission required to make a a connection to the URL. For example, a <code>URLConnection</code> representing a <code>file:</code> URL would return a <code>java.io.FilePermission</code> object. <p>The permission returned may dependent upon the state of the connection. For example, the permission before connecting may be different from that after connecting. For example, an HTTP sever, say foo.com, may redirect the connection to a different host, say bar.com. Before connecting the permission returned by the connection will represent the permission needed to connect to foo.com, while the permission returned after connecting will be to bar.com. <p>Permissions are generally used for two purposes: to protect caches of objects obtained through URLConnections, and to check the right of a recipient to learn about a particular URL. In the first case, the permission should be obtained <em>after</em> the object has been obtained. For example, in an HTTP connection, this will represent the permission to connect to the host from which the data was ultimately fetched. In the second case, the permission should be obtained and tested <em>before</em> connecting.<DD><DL><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/net/URLConnection.html#getPermission()">getPermission</A></CODE> in class <CODE><A HREF="../../java/net/URLConnection.html">URLConnection</A></CODE></DL></DD><DD>Following copied from class: <CODE>java.net.URLConnection</CODE></DD><DD><DL><DT><B>Returns:</B><DD>the permission object representing the permission necessary to make the connection represented by this URLConnection.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if the computation of the permission requires network or file I/O and an exception occurs while computing it.</DL></DD></DL><HR><A NAME="getErrorStream()"><!-- --></A><H3>getErrorStream</H3><PRE>public <A HREF="../../java/io/InputStream.html">InputStream</A> <B>getErrorStream</B>()</PRE><DL><DD>Returns the error stream if the connection failed but the server sent useful data nonetheless. The typical example is when an HTTP server responds with a 404, which will cause a FileNotFoundException to be thrown in connect, but the server sent an HTML help page with suggestions as to what to do. <p>This method will not cause a connection to be initiated. If there the connection was not connected, or if the server did not have an error while connecting or if the server did have an error but there no error data was sent, this method will return null. This is the default.<DD><DL><DT><B>Returns:</B><DD>an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.</DL></DD></DL><!-- ========= END OF CLASS DATA ========= --><HR><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_bottom_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/HttpURLConnection.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/DatagramSocketImpl.html"><B>PREV CLASS</B></A> <A HREF="../../java/net/InetAddress.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="HttpURLConnection.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><font size="-1"><a href="http://java.sun.com/cgi-bin/bugreport.cgi">Submit a bug or feature</a><br>For further API reference and developer documentation, see <a href="http://java.sun.com/products/jdk/1.3/devdocs-vs-specs.html">Java 2 SDK SE Developer Documentation</a>. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. <p>Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road<br>Palo Alto, California, 94303, U.S.A. All Rights Reserved.</font></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -