Skip to content

Request

Request represents an HTTP request with methods, headers, and content.

constructor

Creates a new request to a specified URL. Supported methods: GET, POST.

java
Request request = new Request(String method, String url);

addHeader

Adds a header to the request.

java
request.addHeader(String header, String value);

setUserAgent

Sets the user-agent header for the request.

java
request.setUserAgent(String userAgent);

setConnectTimeout

Sets the connection timeout in milliseconds.

java
request.setConnectTimeout(int timeout);

setReadTimeout

Sets the read timeout in milliseconds.

java
request.setReadTimeout(int timeout);

setContent

Sets the content to be sent with a POST request.

java
request.setContent(String content);

fetch

Executes the request and returns a Response.

java
Response response = request.fetch();