HttpURLConnection status codes in Java

Some of the status codes of HttpURLConnection.

1. HttpURLConnection.HTTP_ACCEPTED

int java.net.HttpURLConnection.HTTP_ACCEPTED: 202 [0xca]

HTTP Status-Code 202: Accepted.

2. HttpURLConnection.HTTP_BAD_GATEWAY

int java.net.HttpURLConnection.HTTP_BAD_GATEWAY: 502 [0x1f6]

HTTP Status-Code 502: Bad Gateway.

3. HttpURLConnection.HTTP_BAD_METHOD

int java.net.HttpURLConnection.HTTP_BAD_METHOD: 405 [0x195]

HTTP Status-Code 405: Method Not Allowed.

4. HttpURLConnection.HTTP_BAD_REQUEST

int java.net.HttpURLConnection.HTTP_BAD_REQUEST: 400 [0x190]

HTTP Status-Code 400: Bad Request.

5. HttpURLConnection.HTTP_CLIENT_TIMEOUT

int java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT: 408 [0x198]

HTTP Status-Code 408: Request Time-Out.

6. HttpURLConnection.HTTP_CONFLICT

int java.net.HttpURLConnection.HTTP_CONFLICT: 409 [0x199]

HTTP Status-Code 409: Conflict.

7. HttpURLConnection.HTTP_CREATED

int java.net.HttpURLConnection.HTTP_CREATED: 201 [0xc9]

HTTP Status-Code 201: Created.

8. HttpURLConnection.HTTP_ENTITY_TOO_LARGE

int java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE: 413 [0x19d]

HTTP Status-Code 413: Request Entity Too Large.

9. HttpURLConnection.HTTP_FORBIDDEN

int java.net.HttpURLConnection.HTTP_FORBIDDEN: 403 [0x193]

HTTP Status-Code 403: Forbidden.

10. HttpURLConnection.HTTP_GATEWAY_TIMEOUT

int java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT: 504 [0x1f8]

HTTP Status-Code 504: Gateway Timeout.

11. HttpURLConnection.HTTP_GONE

int java.net.HttpURLConnection.HTTP_GONE: 410 [0x19a]

HTTP Status-Code 410: Gone.

12. HttpURLConnection.HTTP_INTERNAL_ERROR

int java.net.HttpURLConnection.HTTP_INTERNAL_ERROR: 500 [0x1f4]

HTTP Status-Code 500: Internal Server Error.

13. HttpURLConnection.HTTP_LENGTH_REQUIRED

int java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED: 411 [0x19b]

HTTP Status-Code 411: Length Required.

14. HttpURLConnection.HTTP_MOVED_PERM

int java.net.HttpURLConnection.HTTP_MOVED_PERM: 301 [0x12d]

HTTP Status-Code 301: Moved Permanently.

15. HttpURLConnection.HTTP_MOVED_TEMP 

int java.net.HttpURLConnection.HTTP_MOVED_TEMP: 302 [0x12e]

HTTP Status-Code 302: Temporary Redirect.

16. HttpURLConnection.HTTP_MULT_CHOICE

int java.net.HttpURLConnection.HTTP_MULT_CHOICE: 300 [0x12c]

HTTP Status-Code 300: Multiple Choices.

17. HttpURLConnection.HTTP_NO_CONTENT

int java.net.HttpURLConnection.HTTP_NO_CONTENT: 204 [0xcc]

HTTP Status-Code 204: No Content.

18. HttpURLConnection.HTTP_NOT_ACCEPTABLE

int java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE: 406 [0x196]

HTTP Status-Code 406: Not Acceptable.

19. HttpURLConnection.HTTP_NOT_AUTHORITATIVE 

int java.net.HttpURLConnection.HTTP_NOT_AUTHORITATIVE: 203 [0xcb]

HTTP Status-Code 203: Non-Authoritative Information.

20. HttpURLConnection.HTTP_NOT_FOUND

int java.net.HttpURLConnection.HTTP_NOT_FOUND: 404 [0x194]

HTTP Status-Code 404: Not Found.

21. HttpURLConnection.HTTP_NOT_IMPLEMENTED

int java.net.HttpURLConnection.HTTP_NOT_IMPLEMENTED: 501 [0x1f5]

HTTP Status-Code 501: Not Implemented.

22. HttpURLConnection.HTTP_NOT_MODIFIED

int java.net.HttpURLConnection.HTTP_NOT_MODIFIED: 304 [0x130]

HTTP Status-Code 304: Not Modified.

23. HttpURLConnection.HTTP_OK

int java.net.HttpURLConnection.HTTP_OK: 200 [0xc8]

HTTP Status-Code 200: OK.

24. HttpURLConnection.HTTP_PARTIAL

int java.net.HttpURLConnection.HTTP_PARTIAL : 206 [0xce]

HTTP Status-Code 206: Partial Content.

25. HttpURLConnection.HTTP_PAYMENT_REQUIRED 

int java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED: 402 [0x192]

HTTP Status-Code 402: Payment Required.

26. HttpURLConnection.HTTP_PRECON_FAILED

int java.net.HttpURLConnection.HTTP_PRECON_FAILED: 412 [0x19c]

HTTP Status-Code 412: Precondition Failed.

27. HttpURLConnection.HTTP_PROXY_AUTH

int java.net.HttpURLConnection.HTTP_PROXY_AUTH: 407 [0x197]

HTTP Status-Code 407: Proxy Authentication Required.

28. HttpURLConnection.HTTP_REQ_TOO_LONG

int java.net.HttpURLConnection.HTTP_REQ_TOO_LONG: 414 [0x19e]

HTTP Status-Code 414: Request-URI Too Large.

29. HttpURLConnection.HTTP_RESET

int java.net.HttpURLConnection.HTTP_RESET: 205 [0xcd]

HTTP Status-Code 205: Reset Content.

30. HttpURLConnection.HTTP_SEE_OTHER

int java.net.HttpURLConnection.HTTP_SEE_OTHER: 303 [0x12f]

HTTP Status-Code 303: See Other.

31. HttpURLConnection.HTTP_UNAUTHORIZED

int java.net.HttpURLConnection.HTTP_UNAUTHORIZED: 401 [0x191]

HTTP Status-Code 401: Unauthorized.

32. HttpURLConnection.HTTP_UNAVAILABLE

int java.net.HttpURLConnection.HTTP_UNAVAILABLE: 503 [0x1f7]

HTTP Status-Code 503: Service Unavailable.

33. HttpURLConnection.HTTP_UNSUPPORTED_TYPE

int java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE: 415 [0x19f]

HTTP Status-Code 415: Unsupported Media Type.

34. HttpURLConnection.HTTP_USE_PROXY

int java.net.HttpURLConnection.HTTP_USE_PROXY: 305 [0x131]

HTTP Status-Code 305: Use Proxy.

35. HttpURLConnection.HTTP_VERSION

int java.net.HttpURLConnection.HTTP_VERSION: 505 [0x1f9]

HTTP Status-Code 505: HTTP Version Not Supported.

Approach

Java

package com.HttpURLConnection;

import java.net.HttpURLConnection;

public class HttpURLConnectionConstants {
    public static void main(String[] args) {

        System.out.println(HttpURLConnection.HTTP_ACCEPTED);
        System.out.println(HttpURLConnection.HTTP_BAD_GATEWAY);
        System.out.println(HttpURLConnection.HTTP_BAD_METHOD);
        System.out.println(HttpURLConnection.HTTP_BAD_REQUEST);
        System.out.println(HttpURLConnection.HTTP_CLIENT_TIMEOUT);
        System.out.println(HttpURLConnection.HTTP_CONFLICT);
        System.out.println(HttpURLConnection.HTTP_CREATED);
        System.out.println(HttpURLConnection.HTTP_ENTITY_TOO_LARGE);
        System.out.println(HttpURLConnection.HTTP_FORBIDDEN);
        System.out.println(HttpURLConnection.HTTP_GATEWAY_TIMEOUT);
        System.out.println(HttpURLConnection.HTTP_GONE);
        System.out.println(HttpURLConnection.HTTP_INTERNAL_ERROR);
        System.out.println(HttpURLConnection.HTTP_LENGTH_REQUIRED);
        System.out.println(HttpURLConnection.HTTP_MOVED_PERM);
        System.out.println(HttpURLConnection.HTTP_MOVED_TEMP);
        System.out.println(HttpURLConnection.HTTP_MULT_CHOICE);
        System.out.println(HttpURLConnection.HTTP_NO_CONTENT);

        System.out.println(HttpURLConnection.HTTP_NOT_ACCEPTABLE);
        System.out.println(HttpURLConnection.HTTP_NOT_AUTHORITATIVE);
        System.out.println(HttpURLConnection.HTTP_NOT_FOUND);
        System.out.println(HttpURLConnection.HTTP_NOT_IMPLEMENTED);
        System.out.println(HttpURLConnection.HTTP_NOT_MODIFIED);
        System.out.println(HttpURLConnection.HTTP_OK);
        System.out.println(HttpURLConnection.HTTP_PARTIAL);
        System.out.println(HttpURLConnection.HTTP_PAYMENT_REQUIRED);
        System.out.println(HttpURLConnection.HTTP_PRECON_FAILED);
        System.out.println(HttpURLConnection.HTTP_PROXY_AUTH);
        System.out.println(HttpURLConnection.HTTP_REQ_TOO_LONG);
        System.out.println(HttpURLConnection.HTTP_RESET);
        System.out.println(HttpURLConnection.HTTP_SEE_OTHER);
        System.out.println(HttpURLConnection.HTTP_UNAUTHORIZED);
        System.out.println(HttpURLConnection.HTTP_UNAVAILABLE);
        System.out.println(HttpURLConnection.HTTP_UNSUPPORTED_TYPE);
        System.out.println(HttpURLConnection.HTTP_USE_PROXY);
        System.out.println(HttpURLConnection.HTTP_VERSION);

    }
}

Output:

202 502 405 400 408 409 201 413 403 504 410 500 411 301 302 300 204 406 203 404 501 304 200 206 402 412 407 414 205 303 401 503 415 305 505


Some other methods of HttpURLConnection

HttpURLConnection Status CodeSome 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