Modifier and Type | Field and Description |
---|---|
protected HttpURLConnection |
connection |
protected boolean |
redirect |
protected String |
url |
Constructor and Description |
---|
Request(String url,
int connectTimeout,
int readTimeout) |
Modifier and Type | Method and Description |
---|---|
T |
basic(String user,
String password)
Sets a user and password for basic authentication.
|
byte[] |
bytes()
Fetches response content from server as bytes.
|
protected T |
connect() |
void |
dispose()
|
protected abstract T |
doConnect()
Makes a connection to the remote resource.
|
InputStream |
getInputStream()
Returns input stream to read server response from.
|
T |
header(String name,
String value)
Sets an HTTP header - call before making a request.
|
Map<String,List<String>> |
headers()
Returns HTTP headers as sent by server.
|
T |
redirect(boolean redirect)
Configures this request to follow redirects.
|
int |
responseCode()
Returns HTTP response code.
|
String |
responseMessage()
Returns response message from server, such as "OK", or "Created", etc.
|
String |
text()
Fetches response content from server as String.
|
String |
text(String encoding)
Fetches response content from server as String.
|
protected final HttpURLConnection connection
protected boolean redirect
protected final String url
public Request(String url, int connectTimeout, int readTimeout)
public T header(String name, String value)
name
- header namevalue
- header value.public T redirect(boolean redirect)
false
.redirect
- true to follow, false to not.public InputStream getInputStream()
public Map<String,List<String>> headers()
public int responseCode()
public String responseMessage()
public byte[] bytes()
public String text()
public String text(String encoding)
encoding
- - name of supported charset to apply when reading data.public void dispose()
text()
and bytes()
, you do not have to call it if you use
those methods.
However, if you use getInputStream()
, 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.protected T connect()
protected abstract T doConnect()
Copyright © 2016 JavaLite. All rights reserved.