Class NetworkHandler


  • public class NetworkHandler
    extends Object
    This is a network util class.
    • Field Detail

      • JSON

        public static final @NonNull okhttp3.MediaType JSON
        Used to indicate this http-request accepts JSON
      • TEXT

        public static final @NonNull okhttp3.MediaType TEXT
        Used to indicate this http-request accepts normal String
      • URL_ENCODED

        public static final @NonNull okhttp3.MediaType URL_ENCODED
    • Constructor Detail

      • NetworkHandler

        public NetworkHandler​(NetworkHandler.Options options)
        Initialize a NetworkHandler with specified options
        Parameters:
        options - the options
      • NetworkHandler

        public NetworkHandler()
        Initialize a NetworkHandler with default options
    • Method Detail

      • request

        public HttpResponse request​(String url,
                                    Map<String,​Object> data,
                                    Map<String,​String> header,
                                    okhttp3.MediaType mediaType,
                                    NetworkHandler.RequestType requestType)
        Send a http-request
        Parameters:
        url - the request url
        data - the request data
        header - the request header
        mediaType - the request acceptable type
        requestType - the request type
        Returns:
        the response of this request
      • request

        public HttpResponse request​(String url,
                                    String data,
                                    Map<String,​String> header,
                                    okhttp3.MediaType mediaType,
                                    NetworkHandler.RequestType requestType)
        Send a http-request
        Parameters:
        url - the request url
        data - the request data
        header - the request header
        mediaType - the request acceptable type
        requestType - the request type
        Returns:
        the response of this request
      • put

        public HttpResponse put​(String url,
                                String data,
                                Map<String,​String> header,
                                @NotNull
                                okhttp3.MediaType mediaType)
        Send a PUT http-request
        Parameters:
        url - the request url
        data - the request data
        header - the request header
        mediaType - the request acceptable type
        Returns:
        the response of this request
      • post

        public HttpResponse post​(String url,
                                 String data,
                                 Map<String,​String> header,
                                 @NotNull
                                 okhttp3.MediaType mediaType)
        Send a POST http-request
        Parameters:
        url - the request url
        data - the request data
        header - the request header
        mediaType - the request acceptable type
        Returns:
        the response of this request
      • delete

        public HttpResponse delete​(String url,
                                   String data,
                                   Map<String,​String> header,
                                   @NotNull
                                   okhttp3.MediaType mediaType)
        Send a DELETE http-request
        Parameters:
        url - the request url
        data - the request data
        header - the request header
        mediaType - the request acceptable type
        Returns:
        the response of this request
      • get

        public HttpResponse get​(String url,
                                @NotNull
                                Map<String,​Object> data,
                                Map<String,​String> header)
        Send a GET http-request
        Parameters:
        url - the request url
        data - the request data
        header - the request header
        Returns:
        the response of this request
      • addHandler

        public void addHandler​(HttpHandler handler)
        Add a http handler to this network handler
        Parameters:
        handler - the http handler