JavaXT

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

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

Methods

addHeader( String key, String value ) returns void
Used to add a Request Property to the HTTP header (e.g. "User-Agent").
clone( ) returns javaxt.http.Request
getHeader( String key ) returns java.util.List
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.
getProxy( ) returns String
Returns the http proxy address.
getRequestHeaders( ) returns java.util.Map
getResponse( ) returns javaxt.http.Response
Used to return the response from the server.
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.
isProxyAvailable( String proxyHost, int proxyPort ) returns boolean
Used to check whether a proxy server is online/accessible.
setConnectTimeout( int timeout ) returns void
Connection timeout in milliseconds
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.
setHeader( String key, String value ) returns void
Used to set a Request Property in the HTTP header (e.g. "User-Agent").
setNumRedirects( int maxRedirects ) returns void
Sets the maximum number of redirects to follow. By default, this number is set to 5.
setPassword( String password ) returns void
Used to set the password used to authenticate the client. See setCredentials() for more information.
setProxy( String httpProxy ) returns java.net.Proxy
Used to set the http proxy.
setProxy( java.net.Proxy httpProxy ) returns void
Used to set the http proxy as needed.
setProxy( String proxyHost, int proxyPort ) returns java.net.Proxy
Used to set the http proxy.
setReadTimeout( int timeout ) returns void
Read timeout in milliseconds.
setRequestMethod( String method ) returns void
setURL( java.net.URL url ) returns void
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.
setUserName( String username ) returns void
Used to set the username used to authenticate the client. See setCredentials() for more information.
toString( ) returns String
Returns the request headers sent to the server.
validateSSLCertificates( boolean validateCertificates ) returns void
Used to enable/disable certificate validation for HTTPS Connections. Note that this is set to false by default.
write( java.io.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 to the URL and POST data to the server.
payloadString containing the body of the HTTP request.
write( byte[] payload ) returns void
Used to open an HTTP connection to the URL and POST data to the server.
payloadByte array containing the body of the HTTP request.
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.