Class NetUtils


  • public class NetUtils
    extends Object
    Shared network/http-related utilities and functionality
    • Constructor Summary

      Constructors 
      Constructor Description
      NetUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static okhttp3.OkHttpClient.Builder basicClient()
      Convenience method, creates a new OkHttpBuilder with timeouts configured.
      static okhttp3.Response basicPOST​(okhttp3.OkHttpClient client, okhttp3.HttpUrl baseURL, String endpoint, com.google.gson.JsonObject jo)
      Performs a simple POST to the specified url with the provided client and json data.
      static okhttp3.Response basicPOST​(okhttp3.OkHttpClient client, okhttp3.HttpUrl baseURL, String endpoint, HashMap<String,​String> form)
      Performs a simple form POST to the specified url with the provided client and form data.
      static com.google.gson.JsonObject post​(String url, com.google.gson.JsonObject json)  
      static okhttp3.OkHttpClient unsafeClient()
      Creates a new OkHttpClient which ignores expired/invalid ssl certificates.
    • Constructor Detail

      • NetUtils

        public NetUtils()
    • Method Detail

      • post

        public static com.google.gson.JsonObject post​(String url,
                                                      com.google.gson.JsonObject json)
                                               throws IOException
        Throws:
        IOException
      • basicPOST

        public static okhttp3.Response basicPOST​(okhttp3.OkHttpClient client,
                                                 okhttp3.HttpUrl baseURL,
                                                 String endpoint,
                                                 com.google.gson.JsonObject jo)
                                          throws IOException
        Performs a simple POST to the specified url with the provided client and json data.
        Parameters:
        client - The OkHttp client to use
        baseURL - The base URL to target
        endpoint - The endpoint on the baseURL to target.
        jo - The JsonObject to put in the request body
        Returns:
        The response from the server, in the form of a Response object
        Throws:
        IOException - Network error
      • basicPOST

        public static okhttp3.Response basicPOST​(okhttp3.OkHttpClient client,
                                                 okhttp3.HttpUrl baseURL,
                                                 String endpoint,
                                                 HashMap<String,​String> form)
                                          throws IOException
        Performs a simple form POST to the specified url with the provided client and form data.
        Parameters:
        client - The OkHttp client to use
        baseURL - The base URL to target
        endpoint - The endpoint on the baseURL to target.
        form - The form data to POST
        Returns:
        The response from the server, in the form of a Response object
        Throws:
        IOException - Network error
      • basicClient

        public static okhttp3.OkHttpClient.Builder basicClient()
        Convenience method, creates a new OkHttpBuilder with timeouts configured.
        Returns:
        A OkHttpClient builder with reasonable timeouts configured.
      • unsafeClient

        public static okhttp3.OkHttpClient unsafeClient()
        Creates a new OkHttpClient which ignores expired/invalid ssl certificates. Normally, OkHttp will raise an exception if it encounters bad certificates.
        Returns:
        A new OkHttpClient which ignores expired/invalid ssl certificates.