Request Class

Used to set up a connection to an http server. This class is used in conjunction with the HTTP Response class. Example:
    javaxt.http.Response response = new javaxt.http.Request(url).getResponse();  
A slightly more complex example might look like this:
    javaxt.http.Request request = new javaxt.http.Request(url);
    request.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10)");
    request.setHeader("Accept-Encoding", "deflate"); //no gzip encoding
    java.io.InputStream inputStream = request.getResponse().getInputStream();
    new javaxt.io.File("/temp/image.jpg").write(inputStream);
    inputStream.close();  

Constructors

Request( String url )
Request( String url, String httpProxy )
Request( java.net.URL url )
Request( java.net.URL url, String httpProxy )

Public Methods

getAcceptedIssuers( ) returns java.security.cert.X509Certificate[]
checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType ) returns void
checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType ) returns void
verify( String hostname, SSLSession session ) returns boolean
clone( ) returns Request
setURL( java.net.URL url ) returns void
getURL( ) returns java.net.URL
Returns the URL used to make the request. Note that the URL may be different from the URL used to invoke this class if the request encounters a redirect. See setNumRedirects() for more information. Use the getInitialURL() to get the original URL used to instantiate this class.
getInitialURL( ) returns java.net.URL
Returns the URL used to instantiate this class. This URL may be different from the URL used to execute the request. See getURL() for more information.
setRequestMethod( String method ) returns void
Used to specify the request method ("GET", "POST", "PUT", "DELETE", etc). By default, requests are made using "GET" when fetching data and "POST" when writing data to the server. This method is used to override these defaults (e.g. "PUT" and "DELETE" for REST services).
getResponse( ) returns Response
Used to return the response from the server.
setUseCache( boolean useCache ) returns void
Sets the header associated with cache-control. If true, the protocol is allowed to use caching whenever it can. If false, the protocol must always try to get a fresh copy of the object. By default, the useCache variable is set to false.
validateSSLCertificates( boolean validateCertificates ) returns void
Used to enable/disable certificate validation for HTTPS Connections. By default, certificates are validated via a Certificate Authority (CA). However, there are times where you may not want to validate a site's certificate (e.g. connecting to a intranet site or a development server with self-signed certificate). In these cases, you can bypass the validation process by setting this method to false.
setNumRedirects( int maxRedirects ) returns void
Sets the maximum number of redirects to follow. By default, this number is set to 5.
setCredentials( String username, String password ) returns void
Used to set the username and password used to authenticate the client. The credentials are used in the "Authorization" request header and encoded using "Basic" authentication. Note that credentials encoded using "Basic" authentication can be easily decoded. As a general rule, do not pass credentials to sites that are not secured using SSL.
setUserName( String username ) returns void
Used to set the username used to authenticate the client. See setCredentials() for more information.
setPassword( String password ) returns void
Used to set the password used to authenticate the client. See setCredentials() for more information.
setConnectTimeout( int timeout ) returns void
Connection timeout in milliseconds
setReadTimeout( int timeout ) returns void
Read timeout in milliseconds.
write( InputStream payload ) returns void
Used to open an HTTP connection to the URL and POST data to the server.
payloadInputStream containing the body of the HTTP request.
write( String payload ) returns void
Used to open an HTTP connection and sent data to the server.
payloadString containing the body of the HTTP request.
write( byte[] payload ) returns void
Used to open an HTTP connection and sent data to the server.
payloadByte array containing the body of the HTTP request.
write( javaxt.json.JSONObject json ) returns void
Used to open an HTTP connection and sent a JSON object to the server. Note that the JSON object is encoded using UTF-8. In some applications, the encoding may need to be explicitly defined in the "Content-Type" request header. Example:
    request.setHeader("Content-Type", "application/json;charset=UTF-8");    
write( javaxt.json.JSONArray arr ) returns void
Used to open an HTTP connection and sent a JSON array to the server. Note that the JSON array is encoded using UTF-8. In some applications, the encoding may need to be explicitly defined in the "Content-Type" request header. Example:
    request.setHeader("Content-Type", "application/json;charset=UTF-8");    
write( javaxt.html.Input[] inputs ) returns void
Used to post an array of form inputs to a server. Form inputs can include text or binary data, including files. Payload is normally "multipart/form-data" encoded.
getHeader( String key ) returns List<String>
setHeader( String key, String value ) returns void
Used to set a Request Property in the HTTP header (e.g. "User-Agent").
addHeader( String key, String value ) returns void
Used to add a Request Property to the HTTP header (e.g. "User-Agent").
getRequestHeaders( ) returns Map<String, List<String>>
getProxy( ) returns String
Returns the http proxy address.
setProxy( String proxyHost, int proxyPort ) returns Proxy
Used to set the http proxy.
setProxy( String httpProxy ) returns Proxy
Used to set the http proxy.
setProxy( Proxy httpProxy ) returns void
Used to set the http proxy as needed.
isProxyAvailable( String proxyHost, int proxyPort ) returns boolean
Used to check whether a proxy server is online/accessible.
toString( ) returns String
Returns the request headers sent to the server.