HttpURLConnection getHeaderFieldDate(String, long) in Java

getHeaderFieldDate(String, long): This method is available in java.net.HttpURLConnection class of Java.

Syntax:

long java.net.HttpURLConnection.getHeaderFieldDate(String name, long Default)

This method takes two arguments. This method Returns the value of the named field parsed as a date. The result is the number of milliseconds since January 1, 1970, GMT represented by the named field.

Parameters: Two parameters are required for this method.

name: the name of the header field.

Default: a default value.

Returns: the value of the field, parsed as a date. The value of the Default argument is returned if the field is missing or malformed.

Exceptions: NA

Approach

Java

package com.HttpURLConnection;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpURLConnectiongetHeaderFieldDate {
    public static void main(String[] args) throws IOException {
        URL url =
new URL("https://beingcodeexpert.blogspot.com/");
        HttpURLConnection httpURLConnection =
(HttpURLConnection) url.openConnection();

        String name = "hello";

        long Default = 10;
        System.out.println(httpURLConnection.getHeaderFieldDate(name, Default));

    }
}

Output:

10


Some other methods of HttpURLConnection

HttpURLConnection Status Code: Some of the status codes of HttpURLConnection. example HttpURLConnection.HTTP_ACCEPTED, HttpURLConnection.HTTP_BAD_GATEWAY, etc.

disconnect(): This method indicates that other requests to the server are unlikely in the near future.

getErrorStream(): This method returns the error stream if the connection failed but the server sent useful data nonetheless.

HttpURLConnection.getFollowRedirects(): This method returns a boolean indicating whether or not HTTP redirects (3xx) should be automatically followed.

getHeaderField(int): This method returns the value for the nth header field.

getHeaderFieldDate(String, long): This method Returns the value of the named field parsed as a date. The result is the number of milliseconds since January 1, 1970, GMT represented by the named field.

getHeaderFieldKey(int): This method returns the key for the nth header field.

getInstanceFollowRedirects(): This method returns the value of this HttpURLConnection instanceFollowRedirects field.

getPermission(): This method returns a SocketPermission object representing the permission necessary to connect to the destination host and port.

getRequestMethod(): This method gets the request method.

getResponseCode(): This method gets the status code from an HTTP response message.

getResponseMessage(): This method gets the HTTP response message, if any, returned along with the response code from a server.

setAuthenticator(Authenticator): This method 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.

setChunkedStreamingMode(int): This method is used to enable the streaming of an HTTP request body without internal buffering when the content length is not known in advance.

setFixedLengthStreamingMode(int): This method is used to enable the streaming of an HTTP request body without internal buffering when the content length is known in advance.

setFixedLengthStreamingMode(long): This method is used to enable the streaming of an HTTP request body without internal buffering when the content length is known in advance.

HttpURLConnection.setFollowRedirects(boolean): This method sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class.

setInstanceFollowRedirects(boolean): This method sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance.

setRequestMethod(String): This method sets the method for the URL request, as one of •GET •POST •HEAD •OPTIONS •PUT •DELETE •TRACE are legal, subject to protocol restrictions.

usingProxy(): This method indicates if the connection is going through a proxy.

No comments:

Post a Comment