Package top.focess.util.network
Class NetworkHandler
- java.lang.Object
-
- top.focess.util.network.NetworkHandler
-
public class NetworkHandler extends Object
This is a network util class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNetworkHandler.OptionsNetworkHandler Optionsstatic classNetworkHandler.RequestTypeRepresents a request-type
-
Field Summary
Fields Modifier and Type Field Description static @NonNull okhttp3.MediaTypeJSONUsed to indicate this http-request accepts JSONstatic @NonNull okhttp3.MediaTypeTEXTUsed to indicate this http-request accepts normal Stringstatic @NonNull okhttp3.MediaTypeURL_ENCODED
-
Constructor Summary
Constructors Constructor Description NetworkHandler()Initialize a NetworkHandler with default optionsNetworkHandler(NetworkHandler.Options options)Initialize a NetworkHandler with specified options
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(HttpHandler handler)Add a http handler to this network handlerHttpResponsedelete(String url, String data, Map<String,String> header, okhttp3.MediaType mediaType)Send a DELETE http-requestHttpResponseget(String url, Map<String,Object> data, Map<String,String> header)Send a GET http-requestHttpResponsepost(String url, String data, Map<String,String> header, okhttp3.MediaType mediaType)Send a POST http-requestHttpResponseput(String url, String data, Map<String,String> header, okhttp3.MediaType mediaType)Send a PUT http-requestHttpResponserequest(String url, String data, Map<String,String> header, okhttp3.MediaType mediaType, NetworkHandler.RequestType requestType)Send a http-requestHttpResponserequest(String url, Map<String,Object> data, Map<String,String> header, okhttp3.MediaType mediaType, NetworkHandler.RequestType requestType)Send a http-requestHttpResponserequest(String url, Map<String,Object> data, NetworkHandler.RequestType requestType)Send a http-requestHttpResponserequest(String url, NetworkHandler.RequestType requestType)Send a http-request
-
-
-
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, NetworkHandler.RequestType requestType)
Send a http-request- Parameters:
url- the request urldata- the request datarequestType- the request type- Returns:
- the response of this request
-
request
public HttpResponse request(String url, NetworkHandler.RequestType requestType)
Send a http-request- Parameters:
url- the request urlrequestType- the request type- Returns:
- the response of this request
- See Also:
request(String, Map, RequestType)
-
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 urldata- the request dataheader- the request headermediaType- the request acceptable typerequestType- 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 urldata- the request dataheader- the request headermediaType- the request acceptable typerequestType- 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 urldata- the request dataheader- the request headermediaType- 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 urldata- the request dataheader- the request headermediaType- 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 urldata- the request dataheader- the request headermediaType- 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 urldata- the request dataheader- 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
-
-