Package Java.net.http Does Not Exist Jdk 8

5 views
Skip to first unread message
Message has been deleted

Fanny Lococo

unread,
Jul 17, 2024, 5:04:56 PM7/17/24
to neovoperass

I'm trying to get one of my projects ready for Java 11 but for some reason Intellij can't find java.net.http. It isn't underlining it as not found in module-info.java like it would if I typed it wrong but when I try build the project I get the error below. I've tried reinstalling Intellij 2018.2.3 and uninstalling all other versions of Java. Any advice on how to get this working would be appreciated.

In the case that the above proposed resolution (by @Will) does not solve your issue as was the case with me (i.e. setting the project language level), check to to see what the bytecode target version of your java compiler has been set to, in your project preferences:

package java.net.http does not exist jdk 8


Descargar https://urluss.com/2yODyD



Then I had to adjust the Java Compiler. The Target bytecode version is 11 and I set the project bytecode version Same as language level. Then you don't have to change all of them constantly. Please see picture below.

I am using Java 17 and building with Maven using IntelliJ. IntelliJ uses its own internal command to build the project. To override this behaviour, you must go to Preferences - Build, Execution & Deployment - Build Tools - Maven - Runner and select the option Delegate IDE build/run actions to maven which will essentially run directly from the Maven config file using the mvn tool installed in the system, instead of using the IDE command.

In your module definition, located (based on your package name) in src/org/example/module-info.java, you need to add the dependency to the java.net.http package, which is included in the java.httpclient module:

So you have to change your imports to jdk.incubator.http.*. Furthermore, you must include the module jdk.incubator.httpclient in your module-info.java. When compiling and running your code, add the argument --add-modules=jdk.incubator.httpclient to your invocation of the java and javac executables.

projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/zchartsak/GetSourceWeb/GetSourceWeb.java:17: error: package java.net.http does not exist
[javac] import java.net.http.HttpClient;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/zchartsak/GetSourceWeb/GetSourceWeb.java:18: error: package java.net.http does not exist
[javac] import java.net.http.HttpRequest;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/zchartsak/GetSourceWeb/GetSourceWeb.java:19: error: package java.net.http does not exist
[javac] import java.net.http.HttpResponse;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/zchartsak/GetSourceWeb/GetSourceWeb.java:41: error: cannot find symbol
[javac] HttpClient client = HttpClient.newHttpClient();
[javac] ^
[javac] symbol: class HttpClient

These classes in java.net.http weren't added to the JDK until version 11, but Android still mostly supports Java 7 and 8. If you do end up getting implementations of those classes, you'll need to use jarjar to repackage them to something other than the top-level java namespace because the dex utility will reject them.

Not all systems have support for the IPv6 protocol, and while the Java networking stack will attempt to detect it and use it transparently when available, it is also possible to disable its use with a system property. In the case where IPv6 is not available, or explicitly disabled, Inet6Address are not valid arguments for most networking operations any more. While methods like InetAddress.getByName(java.lang.String) are guaranteed not to return an Inet6Address when looking up host names, it is possible, by passing literals, to create such an object. In which case, most methods, when called with an Inet6Address will throw an Exception.

The NetworkInterface class provides APIs to browse and query all the networking interfaces (e.g. ethernet connection or PPP endpoint) of the local machine. It is through that class that you can check if any of the local interfaces is configured to support IPv6.

Note, all conforming implementations must support at least one NetworkInterface object, which must either be connected to a network, or be a "loopback" interface that can only communicate with entities on the same machine.

A number of classes in the java.net package do provide for a much higher level of abstraction and allow for easy access to resources on the network. The classes are:

  • URI is the class representing a Universal Resource Identifier, as specified in RFC 2396. As the name indicates, this is just an Identifier and doesn't provide directly the means to access the resource.
  • URL is the class representing a Universal Resource Locator, which is both an older concept for URIs and a means to access the resources.
  • URLConnection is created from a URL and is the communication link used to access the resource pointed by the URL. This abstract class will delegate most of the work to the underlying protocol handlers like http or https.
  • HttpURLConnection is a subclass of URLConnection and provides some additional functionalities specific to the HTTP protocol. This API has been superseded by the newer HTTP Client API.

The recommended usage is to use URI to identify resources, then convert it into a URL when it is time to access the resource. From that URL, you can either get the URLConnection for fine control, or get directly the InputStream.

By default the protocol handlers are loaded dynamically from the default location. It is, however, possible to deploy additional protocols handlers as services. Service providers of type URLStreamHandlerProvider are located at runtime, as specified in the URL constructor.

Each HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances. Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time. The HTTP protocol handler has a few settings that can be accessed through System Properties. This covers Proxy settings as well as various other settings.

Security permissions If a security manager is installed, and if a method is called which results in an attempt to open a connection, the caller must possess either:

  • a "connect" SocketPermission to the host/port combination of the destination URL or
  • a URLPermission that permits this request.
If automatic redirection is enabled, and this request is redirected to another destination, then the caller must also have permission to connect to the redirected host/URL.Since:1.1See Also:
  • disconnect()
  • Field SummaryFieldsModifier and TypeFieldDescriptionprotected intchunkLengthThe chunk-length when using chunked encoding streaming mode for output.protected intfixedContentLengthThe fixed content-length when using fixed-length streaming mode.protected longfixedContentLengthLongThe fixed content-length when using fixed-length streaming mode.static final intHTTP_ACCEPTEDHTTP Status-Code 202: Accepted.static final intHTTP_BAD_GATEWAYHTTP Status-Code 502: Bad Gateway.static final intHTTP_BAD_METHODHTTP Status-Code 405: Method Not Allowed.static final intHTTP_BAD_REQUESTHTTP Status-Code 400: Bad Request.static final intHTTP_CLIENT_TIMEOUTHTTP Status-Code 408: Request Time-Out.static final intHTTP_CONFLICTHTTP Status-Code 409: Conflict.static final intHTTP_CREATEDHTTP Status-Code 201: Created.static final intHTTP_ENTITY_TOO_LARGEHTTP Status-Code 413: Request Entity Too Large.static final intHTTP_FORBIDDENHTTP Status-Code 403: Forbidden.static final intHTTP_GATEWAY_TIMEOUTHTTP Status-Code 504: Gateway Timeout.static final intHTTP_GONEHTTP Status-Code 410: Gone.static final intHTTP_INTERNAL_ERRORHTTP Status-Code 500: Internal Server Error.static final intHTTP_LENGTH_REQUIREDHTTP Status-Code 411: Length Required.static final intHTTP_MOVED_PERMHTTP Status-Code 301: Moved Permanently.static final intHTTP_MOVED_TEMPHTTP Status-Code 302: Temporary Redirect.static final intHTTP_MULT_CHOICEHTTP Status-Code 300: Multiple Choices.static final intHTTP_NO_CONTENTHTTP Status-Code 204: No Content.static final intHTTP_NOT_ACCEPTABLEHTTP Status-Code 406: Not Acceptable.static final intHTTP_NOT_AUTHORITATIVEHTTP Status-Code 203: Non-Authoritative Information.static final intHTTP_NOT_FOUNDHTTP Status-Code 404: Not Found.static final intHTTP_NOT_IMPLEMENTEDHTTP Status-Code 501: Not Implemented.static final intHTTP_NOT_MODIFIEDHTTP Status-Code 304: Not Modified.static final intHTTP_OKHTTP Status-Code 200: OK.static final intHTTP_PARTIALHTTP Status-Code 206: Partial Content.static final intHTTP_PAYMENT_REQUIREDHTTP Status-Code 402: Payment Required.static final intHTTP_PRECON_FAILEDHTTP Status-Code 412: Precondition Failed.static final intHTTP_PROXY_AUTHHTTP Status-Code 407: Proxy Authentication Required.static final intHTTP_REQ_TOO_LONGHTTP Status-Code 414: Request-URI Too Large.static final intHTTP_RESETHTTP Status-Code 205: Reset Content.static final intHTTP_SEE_OTHERHTTP Status-Code 303: See Other.static final intHTTP_SERVER_ERRORDeprecated.it is misplaced and shouldn't have existed.static final intHTTP_UNAUTHORIZEDHTTP Status-Code 401: Unauthorized.static final intHTTP_UNAVAILABLEHTTP Status-Code 503: Service Unavailable.static final intHTTP_UNSUPPORTED_TYPEHTTP Status-Code 415: Unsupported Media Type.static final intHTTP_USE_PROXYHTTP Status-Code 305: Use Proxy.static final intHTTP_VERSIONHTTP Status-Code 505: HTTP Version Not Supported.protected booleaninstanceFollowRedirectsIf true, the protocol will automatically follow redirects.protected StringmethodThe HTTP method (GET,POST,PUT,etc.).protected intresponseCodeAn int representing the three digit HTTP Status-Code.protected StringresponseMessageThe HTTP response message.Fields declared in class java.net.URLConnectionallowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
  • Constructor SummaryConstructorsModifierConstructorDescriptionprotected HttpURLConnection(URL u)Constructor for the HttpURLConnection.
  • Method SummaryAll MethodsStatic MethodsInstance MethodsAbstract MethodsConcrete MethodsModifier and TypeMethodDescriptionabstract voiddisconnect()Indicates that other requests to the server are unlikely in the near future.InputStreamgetErrorStream()Returns the error stream if the connection failed but the server sent useful data nonetheless.static booleangetFollowRedirects()Returns a boolean indicating whether or not HTTP redirects (3xx) should be automatically followed.StringgetHeaderField(int n)Returns the value for the nth header field.StringgetHeaderFieldKey(int n)Returns the key for the nth header field.booleangetInstanceFollowRedirects()Returns the value of this HttpURLConnection's instanceFollowRedirects field.PermissiongetPermission()Returns a SocketPermission object representing the permission necessary to connect to the destination host and port.StringgetRequestMethod()Get the request method.intgetResponseCode()Gets the status code from an HTTP response message.StringgetResponseMessage()Gets the HTTP response message, if any, returned along with the response code from a server.voidsetAuthenticator(Authenticator auth)Supplies an Authenticator to be used when authentication is requested through the HTTP protocol for this HttpURLConnection.voidsetChunkedStreamingMode(int chunklen)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance.voidsetFixedLengthStreamingMode(int contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.voidsetFixedLengthStreamingMode(long contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.static voidsetFollowRedirects(boolean set)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class.voidsetInstanceFollowRedirects(boolean followRedirects)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance.voidsetRequestMethod(String method)Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions.abstract booleanusingProxy()Indicates if the connection is going through a proxy.Methods declared in class java.net.URLConnectionaddRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toStringMethods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details
  • methodprotected String methodThe HTTP method (GET,POST,PUT,etc.).
  • chunkLengthprotected int chunkLengthThe chunk-length when using chunked encoding streaming mode for output. A value of -1 means chunked encoding is disabled for output.Since:1.5
  • fixedContentLengthprotected int fixedContentLengthThe fixed content-length when using fixed-length streaming mode. A value of -1 means fixed-length streaming mode is disabled for output. NOTE: fixedContentLengthLong is recommended instead of this field, as it allows larger content lengths to be set.Since:1.5
  • fixedContentLengthLongprotected long fixedContentLengthLongThe fixed content-length when using fixed-length streaming mode. A value of -1 means fixed-length streaming mode is disabled for output.Since:1.7
  • responseCodeprotected int responseCodeAn int representing the three digit HTTP Status-Code.
    • 1xx: Informational
    • 2xx: Success
    • 3xx: Redirection
    • 4xx: Client Error
    • 5xx: Server Error
  • responseMessageprotected String responseMessageThe HTTP response message.
  • instanceFollowRedirectsprotected boolean instanceFollowRedirectsIf true, the protocol will automatically follow redirects. If false, the protocol will not automatically follow redirects. This field is set by the setInstanceFollowRedirects method. Its value is returned by the getInstanceFollowRedirects method. Its default value is based on the value of the static followRedirects at HttpURLConnection construction time.See Also:
  • setInstanceFollowRedirects(boolean)
  • getInstanceFollowRedirects()
  • setFollowRedirects(boolean)
  • HTTP_OKpublic static final int HTTP_OKHTTP Status-Code 200: OK.See Also:
  • Constant Field Values
  • HTTP_CREATEDpublic static final int HTTP_CREATEDHTTP Status-Code 201: Created.See Also:
  • Constant Field Values
  • HTTP_ACCEPTEDpublic static final int HTTP_ACCEPTEDHTTP Status-Code 202: Accepted.See Also:
  • Constant Field Values
  • HTTP_NOT_AUTHORITATIVEpublic static final int HTTP_NOT_AUTHORITATIVEHTTP Status-Code 203: Non-Authoritative Information.See Also:
  • Constant Field Values
  • HTTP_NO_CONTENTpublic static final int HTTP_NO_CONTENTHTTP Status-Code 204: No Content.See Also:
  • Constant Field Values
  • HTTP_RESETpublic static final int HTTP_RESETHTTP Status-Code 205: Reset Content.See Also:
  • Constant Field Values
  • HTTP_PARTIALpublic static final int HTTP_PARTIALHTTP Status-Code 206: Partial Content.See Also:
  • Constant Field Values
  • HTTP_MULT_CHOICEpublic static final int HTTP_MULT_CHOICEHTTP Status-Code 300: Multiple Choices.See Also:
  • Constant Field Values
  • HTTP_MOVED_PERMpublic static final int HTTP_MOVED_PERMHTTP Status-Code 301: Moved Permanently.See Also:
  • Constant Field Values
  • HTTP_MOVED_TEMPpublic static final int HTTP_MOVED_TEMPHTTP Status-Code 302: Temporary Redirect.See Also:
  • Constant Field Values
  • HTTP_SEE_OTHERpublic static final int HTTP_SEE_OTHERHTTP Status-Code 303: See Other.See Also:
  • Constant Field Values
  • HTTP_NOT_MODIFIEDpublic static final int HTTP_NOT_MODIFIEDHTTP Status-Code 304: Not Modified.See Also:
  • Constant Field Values
  • HTTP_USE_PROXYpublic static final int HTTP_USE_PROXYHTTP Status-Code 305: Use Proxy.See Also:
  • Constant Field Values
  • HTTP_BAD_REQUESTpublic static final int HTTP_BAD_REQUESTHTTP Status-Code 400: Bad Request.See Also:
  • Constant Field Values
  • HTTP_UNAUTHORIZEDpublic static final int HTTP_UNAUTHORIZEDHTTP Status-Code 401: Unauthorized.See Also:
  • Constant Field Values
  • HTTP_PAYMENT_REQUIREDpublic static final int HTTP_PAYMENT_REQUIREDHTTP Status-Code 402: Payment Required.See Also:
  • Constant Field Values
  • HTTP_FORBIDDENpublic static final int HTTP_FORBIDDENHTTP Status-Code 403: Forbidden.See Also:
  • Constant Field Values
  • HTTP_NOT_FOUNDpublic static final int HTTP_NOT_FOUNDHTTP Status-Code 404: Not Found.See Also:
  • Constant Field Values
  • HTTP_BAD_METHODpublic static final int HTTP_BAD_METHODHTTP Status-Code 405: Method Not Allowed.See Also:
  • Constant Field Values
  • HTTP_NOT_ACCEPTABLEpublic static final int HTTP_NOT_ACCEPTABLEHTTP Status-Code 406: Not Acceptable.See Also:
  • Constant Field Values
  • HTTP_PROXY_AUTHpublic static final int HTTP_PROXY_AUTHHTTP Status-Code 407: Proxy Authentication Required.See Also:
  • Constant Field Values
  • HTTP_CLIENT_TIMEOUTpublic static final int HTTP_CLIENT_TIMEOUTHTTP Status-Code 408: Request Time-Out.See Also:
  • Constant Field Values
  • HTTP_CONFLICTpublic static final int HTTP_CONFLICTHTTP Status-Code 409: Conflict.See Also:
  • Constant Field Values
  • HTTP_GONEpublic static final int HTTP_GONEHTTP Status-Code 410: Gone.See Also:
  • Constant Field Values
  • HTTP_LENGTH_REQUIREDpublic static final int HTTP_LENGTH_REQUIREDHTTP Status-Code 411: Length Required.See Also:
  • Constant Field Values
  • HTTP_PRECON_FAILEDpublic static final int HTTP_PRECON_FAILEDHTTP Status-Code 412: Precondition Failed.See Also:
  • Constant Field Values
  • HTTP_ENTITY_TOO_LARGEpublic static final int HTTP_ENTITY_TOO_LARGEHTTP Status-Code 413: Request Entity Too Large.See Also:
  • Constant Field Values
  • HTTP_REQ_TOO_LONGpublic static final int HTTP_REQ_TOO_LONGHTTP Status-Code 414: Request-URI Too Large.See Also:
  • Constant Field Values
  • HTTP_UNSUPPORTED_TYPEpublic static final int HTTP_UNSUPPORTED_TYPEHTTP Status-Code 415: Unsupported Media Type.See Also:
  • Constant Field Values
  • HTTP_SERVER_ERROR@Deprecatedpublic static final int HTTP_SERVER_ERRORDeprecated.it is misplaced and shouldn't have existed.HTTP Status-Code 500: Internal Server Error.See Also:
  • Constant Field Values
  • HTTP_INTERNAL_ERRORpublic static final int HTTP_INTERNAL_ERRORHTTP Status-Code 500: Internal Server Error.See Also:
  • Constant Field Values
  • HTTP_NOT_IMPLEMENTEDpublic static final int HTTP_NOT_IMPLEMENTEDHTTP Status-Code 501: Not Implemented.See Also:
  • Constant Field Values
  • HTTP_BAD_GATEWAYpublic static final int HTTP_BAD_GATEWAYHTTP Status-Code 502: Bad Gateway.See Also:
  • Constant Field Values
  • HTTP_UNAVAILABLEpublic static final int HTTP_UNAVAILABLEHTTP Status-Code 503: Service Unavailable.See Also:
  • Constant Field Values
  • HTTP_GATEWAY_TIMEOUTpublic static final int HTTP_GATEWAY_TIMEOUTHTTP Status-Code 504: Gateway Timeout.See Also:
  • Constant Field Values
  • HTTP_VERSIONpublic static final int HTTP_VERSIONHTTP Status-Code 505: HTTP Version Not Supported.See Also:
  • Constant Field Values
  • Constructor Details
  • HttpURLConnectionprotected HttpURLConnection(URL u)Constructor for the HttpURLConnection.Parameters:u - the URL
  • Method Details
  • setAuthenticatorpublic void setAuthenticator(Authenticator auth)Supplies an Authenticator to be used when authentication is requested through the HTTP protocol for this HttpURLConnection. If no authenticator is supplied, the default authenticator will be used.Implementation Requirements:The default behavior of this method is to unconditionally throw UnsupportedOperationException. Concrete implementations of HttpURLConnection which support supplying an Authenticator for a specific HttpURLConnection instance should override this method to implement a different behavior.Implementation Note:Depending on authentication schemes, an implementation may or may not need to use the provided authenticator to obtain a password. For instance, an implementation that relies on third-party security libraries may still invoke the default authenticator if these libraries are configured to do so. Likewise, an implementation that supports transparent NTLM authentication may let the system attempt to connect using the system user credentials first, before invoking the provided authenticator.
    However, if an authenticator is specifically provided, then the underlying connection may only be reused for HttpURLConnection instances which share the same Authenticator instance, and authentication information, if cached, may only be reused for an HttpURLConnection sharing that same Authenticator.Parameters:auth - The Authenticator that should be used by this HttpURLConnection.Throws:UnsupportedOperationException - if setting an Authenticator is not supported by the underlying implementation.IllegalStateException - if URLConnection is already connected.NullPointerException - if the supplied auth is null.Since:9
  • getHeaderFieldKeypublic String getHeaderFieldKey(int n)Returns the key for the nth header field. Some implementations may treat the 0th header field as special, i.e. as the status line returned by the HTTP server. In this case, getHeaderField(0) returns the status line, but getHeaderFieldKey(0) returns null.Overrides:getHeaderFieldKey in class URLConnectionParameters:n - an index, where n >=0.Returns:the key for the nth header field, or null if the key does not exist.
  • setFixedLengthStreamingModepublic void setFixedLengthStreamingMode(int contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance. An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount. When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error. This method must be called before the URLConnection is connected. NOTE: setFixedLengthStreamingMode(long) is recommended instead of this method as it allows larger content lengths to be set.Parameters:contentLength - The number of bytes which will be written to the OutputStream.Throws:IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.IllegalArgumentException - if a content length less than zero is specified.Since:1.5See Also:
  • setChunkedStreamingMode(int)
  • setFixedLengthStreamingModepublic void setFixedLengthStreamingMode(long contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance. An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount. When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error. This method must be called before the URLConnection is connected. The content length set by invoking this method takes precedence over any value set by setFixedLengthStreamingMode(int).Parameters:contentLength - The number of bytes which will be written to the OutputStream.Throws:IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.IllegalArgumentException - if a content length less than zero is specified.Since:1.7
  • setChunkedStreamingModepublic void setChunkedStreamingMode(int chunklen)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance. In this mode, chunked transfer encoding is used to send the request body. Note, not all HTTP servers support this mode. When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error. This method must be called before the URLConnection is connected.Parameters:chunklen - The number of bytes to be written in each chunk, including a chunk size header as a hexadecimal string (minimum of 1 byte), two CRLF's (4 bytes) and a minimum payload length of 1 byte. If chunklen is less than or equal to 5, a higher default value will be used.Throws:IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.Since:1.5See Also:
  • setFixedLengthStreamingMode(int)
  • getHeaderFieldpublic String getHeaderField(int n)Returns the value for the nth header field. Some implementations may treat the 0th header field as special, i.e. as the status line returned by the HTTP server. This method can be used in conjunction with the getHeaderFieldKey method to iterate through all the headers in the message.Overrides:getHeaderField in class URLConnectionParameters:n - an index, where n>=0.Returns:the value of the nth header field, or null if the value does not exist.See Also:
  • getHeaderFieldKey(int)
  • setFollowRedirectspublic static void setFollowRedirects(boolean set)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class. True by default. Applets cannot change this variable. 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.Parameters:set - a boolean indicating whether or not to follow HTTP redirects.Throws:SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation.See Also:
  • SecurityManager.checkSetFactory()
  • getFollowRedirects()
  • getFollowRedirectspublic static boolean getFollowRedirects()Returns a boolean indicating whether or not HTTP redirects (3xx) should be automatically followed.Returns:true if HTTP redirects should be automatically followed, false if not.See Also:
  • setFollowRedirects(boolean)
  • setInstanceFollowRedirectspublic void setInstanceFollowRedirects(boolean followRedirects)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance. The default value comes from followRedirects, which defaults to true.Parameters:followRedirects - a boolean indicating whether or not to follow HTTP redirects.Since:1.3See Also:
  • instanceFollowRedirects
  • getInstanceFollowRedirects()
  • getInstanceFollowRedirectspublic boolean getInstanceFollowRedirects()Returns the value of this HttpURLConnection's instanceFollowRedirects field.Returns:the value of this HttpURLConnection's instanceFollowRedirects field.Since:1.3See Also:
  • instanceFollowRedirects
  • setInstanceFollowRedirects(boolean)
  • setRequestMethodpublic void setRequestMethod(String method) throws ProtocolExceptionSet the method for the URL request, one of:
    • GET
    • POST
    • HEAD
    • OPTIONS
    • PUT
    • DELETE
    • TRACE
    are legal, subject to protocol restrictions. The default method is GET.Parameters:method - the HTTP methodThrows:ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.SecurityException - if a security manager is set and the method is "TRACE", but the "allowHttpTrace" NetPermission is not granted.See Also:
  • getRequestMethod()
  • getRequestMethodpublic String getRequestMethod()Get the requ

Reply all
Reply to author
Forward
0 new messages