Class NetUtils

java.lang.Object
ai.devtools.utils.NetUtils

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static okhttp3.OkHttpClient.Builder
    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
    Creates a new OkHttpClient which ignores expired/invalid ssl certificates.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NetUtils

      public NetUtils()
  • Method Details

    • 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.