Class NetworkHandler


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

      • JSON

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

        public static final okhttp3.MediaType TEXT
        Used to indicate this http-request accepts normal String
    • Constructor Detail

      • NetworkHandler

        public NetworkHandler()
    • 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
      • put

        public HttpResponse put​(String url,
                                Map<String,​Object> data,
                                Map<String,​String> header,
                                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,
                                 Map<String,​Object> data,
                                 Map<String,​String> header,
                                 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
      • get

        public HttpResponse get​(String url,
                                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