Package open.java.toolkit.http
Class Request
- java.lang.Object
-
- open.java.toolkit.http.Request
-
public class Request extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Request()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddHeader(java.lang.String name, java.lang.String value)Adds a header to the current request.static java.net.http.HttpClient.BuildergetBuilder()Gets the current HttpClient builder.voidrandomizeUserAgent()Randomizes the current User-Agent.static java.net.http.HttpResponse<?>send(java.lang.String url, java.lang.String method, java.net.http.HttpRequest.BodyPublisher publisher)Sends a HTTP(S) request to a specific URL, with a specific method and BodyPublisher.static java.util.concurrent.CompletableFuture<?>sendAsync(java.lang.String url, java.lang.String method, java.net.http.HttpRequest.BodyPublisher publisher)Sends an asynchronous HTTP(S) request to a specific URL, with a specific method and BodyPublisher.static voidsetBodyHandler(java.net.http.HttpResponse.BodyHandler<?> handler)Sets the HttpResponse BodyHandler to a new one.static voidsetContentType(java.lang.String contentType)Sets the Content-Type string to a new one.static voidsetProxy(java.lang.String proxy)Sets the proxy to be used within the current request.static voidsetTimeout(int timeout)Sets the current request timeout to a new one.static voidsetUserAgent(java.lang.String userAgent)Sets the User-Agent string to a new one.
-
-
-
Method Detail
-
getBuilder
public static java.net.http.HttpClient.Builder getBuilder()
Gets the current HttpClient builder.- Returns:
- The current HttpClient builder.
-
setUserAgent
public static void setUserAgent(java.lang.String userAgent)
Sets the User-Agent string to a new one.- Parameters:
userAgent- The new User-Agent string.
-
setContentType
public static void setContentType(java.lang.String contentType)
Sets the Content-Type string to a new one.- Parameters:
contentType- The new Content-Type string.
-
setBodyHandler
public static void setBodyHandler(java.net.http.HttpResponse.BodyHandler<?> handler)
Sets the HttpResponse BodyHandler to a new one.- Parameters:
handler- The new HttpResponse BodyHandler.
-
setTimeout
public static void setTimeout(int timeout)
Sets the current request timeout to a new one.- Parameters:
timeout- The new timeout integer, in milliseconds.
-
addHeader
public static void addHeader(java.lang.String name, java.lang.String value)Adds a header to the current request.- Parameters:
name- The header name.value- The header value.
-
setProxy
public static void setProxy(java.lang.String proxy)
Sets the proxy to be used within the current request.- Parameters:
proxy- The new proxy string, containing both IP and port with a colon separating both.
-
randomizeUserAgent
public void randomizeUserAgent()
Randomizes the current User-Agent.
-
send
public static java.net.http.HttpResponse<?> send(java.lang.String url, java.lang.String method, java.net.http.HttpRequest.BodyPublisher publisher)Sends a HTTP(S) request to a specific URL, with a specific method and BodyPublisher.- Parameters:
url- The URL to perform the request to.method- The method to perform the request with.publisher- The BodyPublisher to perform the request with.- Returns:
- A HttpResponse object.
-
sendAsync
public static java.util.concurrent.CompletableFuture<?> sendAsync(java.lang.String url, java.lang.String method, java.net.http.HttpRequest.BodyPublisher publisher)Sends an asynchronous HTTP(S) request to a specific URL, with a specific method and BodyPublisher.- Parameters:
url- The URL to perform the request to.method- The method to perform the request with.publisher- The BodyPublisher to perform the request with.- Returns:
- A CompletableFuture object containing a HttpResponse object.
-
-