Package org.javalite.http
Class Request<T extends Request>
java.lang.Object
org.javalite.http.Request<T>
This class provides static convenience methods for simple HTTP requests.
- Author:
- Igor Polevoy
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSet a user authenticationSets a user and password for basic authentication.byte[]bytes()Fetches response content from server as bytes.protected Tconnect()voiddispose()protected abstract TMakes a connection to the remote resource.Returns input stream to read server response from.Sets an HTTP header - call before making a request.headers()Returns HTTP headers as sent by server.redirect(boolean redirect)Configures this request to follow redirects.intReturns HTTP response code.Returns response message from server, such as "OK", or "Created", etc.text()Fetches response content from server as String.Fetches response content from server as String.
-
Field Details
-
connection
-
redirect
protected boolean redirect -
url
-
-
Constructor Details
-
Request
-
-
Method Details
-
header
Sets an HTTP header - call before making a request.- Parameters:
name- header namevalue- header value.- Returns:
- self.
-
redirect
Configures this request to follow redirects. Default isfalse.- Parameters:
redirect- true to follow, false to not.- Returns:
- self
- See Also:
- HttpURLConnection.html#instanceFollowRedirects
-
getInputStream
Returns input stream to read server response from.- Returns:
- input stream to read server response from.
-
headers
Returns HTTP headers as sent by server.- Returns:
- HTTP headers as sent by server.
-
responseCode
public int responseCode()Returns HTTP response code.- Returns:
- HTTP response code.
-
responseMessage
Returns response message from server, such as "OK", or "Created", etc.- Returns:
- response message from server, such as "OK", or "Created", etc.
-
bytes
public byte[] bytes()Fetches response content from server as bytes.- Returns:
- response content from server as bytes.
-
text
Fetches response content from server as String.- Returns:
- response content from server as String.
-
text
Fetches response content from server as String.- Parameters:
encoding- - name of supported charset to apply when reading data.- Returns:
- response content from server as String.
-
dispose
public void dispose()This method is already called fromtext()andbytes(), you do not have to call it if you use those methods. However, if you usegetInputStream(), call this method in those cases when you think you did not read entire content from the stream. This method clears all remaining data in connections after reading a response. This will help keep-alive work smoothly. -
connect
-
doConnect
Makes a connection to the remote resource.- Returns:
- self.
-
basic
Sets a user and password for basic authentication.- Parameters:
user- user.password- password.- Returns:
- self.
-
basic
Set a user authentication- Parameters:
user- user- Returns:
- self
-