Class HttpSupport


  • public class HttpSupport
    extends Object
    Extra utilities to support usage of HTTP.
    • Method Detail

      • encode

        public static void encode​(StringBuilder urlstr,
                                  String key)
        URL encode a value string into an output buffer.
        Parameters:
        urlstr - the output buffer.
        key - value which must be encoded to protected special characters.
      • response

        public static int response​(HttpConnection c)
                            throws IOException
        Get the HTTP response code from the request.

        Roughly the same as c.getResponseCode() but the ConnectException is translated to be more understandable.

        Parameters:
        c - connection the code should be obtained from.
        Returns:
        r HTTP status code, usually 200 to indicate success. See HttpConnection for other defined constants.
        Throws:
        IOException - communications error prevented obtaining the response code.
        Since:
        3.3
      • response

        public static int response​(HttpURLConnection c)
                            throws IOException
        Get the HTTP response code from the request.

        Roughly the same as c.getResponseCode() but the ConnectException is translated to be more understandable.

        Parameters:
        c - connection the code should be obtained from.
        Returns:
        r HTTP status code, usually 200 to indicate success. See HttpConnection for other defined constants.
        Throws:
        IOException - communications error prevented obtaining the response code.
      • proxyFor

        public static Proxy proxyFor​(ProxySelector proxySelector,
                                     URL u)
                              throws ConnectException
        Determine the proxy server (if any) needed to obtain a URL.
        Parameters:
        proxySelector - proxy support for the caller.
        u - location of the server caller wants to talk to.
        Returns:
        proxy to communicate with the supplied URL.
        Throws:
        ConnectException - the proxy could not be computed as the supplied URL could not be read. This failure should never occur.