public class Request<ContentType> extends Object
| Constructor and Description |
|---|
Request(String httpMethod,
String url,
HashMap<String,String> headers,
ContentType content)
Fully initialized request
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(String name,
String value)
Add a new header field with specified value to the request
|
void |
cancel()
Cancel the request, disconnecting it from the server
|
HttpURLConnection |
getConnection()
Get the current connection object
|
InputStream |
send()
Send the request to the requested url and retrieve the server answer as an input stream.
|
void |
setContent(ContentType content)
Set the request content, to be sent through the request connection output stream
|
void |
setMethod(String httpMethod)
Set the HTTP method to use with the request
|
void |
setRequestUrl(String url)
Set the request URL.
|
public Request(String httpMethod, String url, HashMap<String,String> headers, ContentType content) throws Exception, MalformedURLException
httpMethod - possible values: "GET", "POST", "PUT", "DELETE", "HEAD", "CONNECT", "OPTIONS", "TRACE", "PATCH"url - a string of the complete request URL (including URL parameters like "?voice=smtg)"headers - HTTP headers of the request
Use null to unset all headers.
content - content to send with the request (often associated with POST requests)
Use null for requests without content
Exception - if the http method is not one of the list aboveMalformedURLException - if the url is not validpublic void addHeader(String name, String value)
name - name of the header fieldvalue - value set for the fieldpublic void setContent(ContentType content)
content - content of the requestpublic void setRequestUrl(String url) throws MalformedURLException
If a previous connection was opened for the current request, close and destroy it.
MalformedURLExceptionpublic void setMethod(String httpMethod) throws Exception
httpMethod - one of the following values: "GET", "POST", "PUT", "DELETE", "HEAD", "CONNECT", "OPTIONS", "TRACE", "PATCH"Exception - if the HTTP method value is not a valid onepublic InputStream send() throws IOException, InterruptedException
IOException - if an error occured during the connection or while sending data to the serverInterruptedException - if the current thead is interrupted while getting the response from the serverpublic HttpURLConnection getConnection()
public void cancel()
Copyright © 2010–2025 The DAISY Consortium. All rights reserved.