Class HTTPClient.HTTPConnection
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class HTTPClient.HTTPConnection

java.lang.Object
   |
   +----HTTPClient.HTTPConnection

public class HTTPConnection
extends Object
This class implements http protocol requests; it contains most of HTTP/1.1 and ought to be unconditionally compliant. Redirections are automatically handled, and authorizations requests are recognized and dealt with via an authorization handler. Only full HTTP/1.0 and HTTP/1.1 requests are generated. HTTP/1.1, HTTP/1.0 and HTTP/0.9 responses are recognized.

Using the HTTPClient should be quite simple. First add the import statement 'import HTTPClient.*;' to your file(s). Request can then be sent using one of the methods Head(), Get(), Post(), etc in HTTPConnection. These methods all return an instance of HTTPResponse which has methods for accessing the response headers (getHeader(), getHeaderAsInt(), etc), various response info (getStatusCode(), getReasonLine(), etc) and the reponse data (getData() and getInputStream()). Following are some examples.

If this is in an applet you can retrieve files from your server as follows:

    HTTPConnection con = new HTTPConnection(this);
    HTTPResponse   rsp = con.Get("/my_file");
    if (rsp.getStatusCode() >= 300)
    {
	System.err.println("Received Error: "+rsp.getReasonLine());
	System.err.println(new String(rsp.getData(),0));
    }
    else
	data = rsp.getData();
    rsp = con.Get("/another_file");
    if (rsp.getStatusCode() >= 300)
    {
	System.err.println("Received Error: "+rsp.getReasonLine());
	System.err.println(new String(rsp.getData(),0));
    }
    else
	other_data = rsp.getData();
This will get the files "/my_file" and "/another_file" and put their contents into byte[]'s accessible via getData(). Note that you need to only create a new HTTPConnection when sending a request to a new server (different host or port); although you may create a new HTTPConnection for every request to the same server this not recommended, as various information about the server is cached after the first request (to optimize subsequent requests) and persistent connections are used whenever possible.

To POST form data you would use something like this (assuming you have two fields called name and e-mail, whose contents are stored in the variables name and email):

    NVPair form_data[] = new NVPair[2];
    form_data[0] = new NVPair("name", name);
    form_data[1] = new NVPair("e-mail", email);
    HTTPConnection con = new HTTPConnection(this);
    HTTPResponse   rsp = con.Post("/cgi-bin/my_script", form_data);
    if (rsp.getStatusCode() >= 300)
    {
	System.err.println("Received Error: "+rsp.getReasonLine());
	System.err.println(new String(rsp.getData(),0));
    }
    else
        stream = rsp.getInputStream();
Here the response data is read at leasure via an InputStream instead of all at once into a byte[].

As another example, if you have a URL you're trying to send a request to you would do something like the following:

    URL url = new URL("http://www.mydomain.us/test/my_file");
    HTTPConnection con = new HTTPConnection(url);
    HTTPResponse   rsp = con.Put(url.getFile(), "Hello World");
    if (rsp.getStatusCode() >= 300)
    {
	System.err.println("Received Error: "+rsp.getReasonLine());
	System.err.println(new String(rsp.getData(),0));
    }
    else
        data = rsp.getData();

There are a whole number of methods for each request type; however the general form's are:

Version:
0.2 (bug fix 2) 23/03/1997
Author:
Ronald Tschalär

Variable Index

 o version
Current version

Constructor Index

 o HTTPConnection(Applet)
Constructs a connection to the host from where the applet was loaded.
 o HTTPConnection(String)
Constructs a connection to the specified host on port 80
 o HTTPConnection(String, int)
Constructs a connection to the specified host on the specified port
 o HTTPConnection(String, String, int)
Constructs a connection to the specified host on the specified port, using the specified protocol (currently only "http" is supported).
 o HTTPConnection(URL)
Constructs a connection to the host (port) as given in the url.

Method Index

 o addAuthorization(String, String, String, NVPair[])
Add's an authorization entry to the list.
 o addBasicAuthorization(String, String, String)
Add's an authorization entry for the "basic" authorization scheme to the list.
 o Delete(String)
Requests that file be DELETEd from the server.
 o Delete(String, NVPair[])
Requests that file be DELETEd from the server.
 o ExtensionMethod(String, String, byte[], NVPair[])
This is here to allow an arbitrary, non-standard request to be sent.
 o Get(String)
GET's the file.
 o Get(String, NVPair[])
GET's the file with a query consisting of the specified form-data.
 o Get(String, NVPair[], NVPair[])
GET's the file with a query consisting of the specified form-data.
 o Get(String, String)
GET's the file using the specified query string.
 o Get(String, String, NVPair[])
GET's the file using the specified query string.
 o getDefaultHeaders()
Gets the current list of default http headers.
 o Head(String)
Sends the HEAD request.
 o Head(String, NVPair[])
Sends the HEAD request.
 o Head(String, NVPair[], NVPair[])
Sends the HEAD request.
 o Head(String, String)
Sends the HEAD request.
 o Head(String, String, NVPair[])
Sends the HEAD request.
 o Options(String)
Request OPTIONS from the server.
 o Options(String, NVPair[])
Request OPTIONS from the server.
 o Post(String)
POST's to the specified file.
 o Post(String, byte[])
POST's the raw data to the specified file.
 o Post(String, byte[], NVPair[])
POST's the raw data to the specified file using the specified headers.
 o Post(String, NVPair[])
POST's form-data to the specified file.
 o Post(String, String)
POST's the data to the specified file.
 o Post(String, String, NVPair[])
POST's the data to the specified file using the specified headers.
 o Put(String, byte[])
PUT's the raw data into the specified file.
 o Put(String, byte[], NVPair[])
PUT's the raw data into the specified file using the additional headers.
 o Put(String, String)
PUT's the data into the specified file.
 o Put(String, String, NVPair[])
PUT's the data into the specified file using the additional headers for the request.
 o setDefaultHeaders(NVPair[])
Sets the default http headers to be sent with each request.
 o setProxyServer(String, int)
Set's the default proxy server to use.
 o setRawMode(boolean)
Sets/Resets raw mode.
 o setSocksServer(String)
Set's the SOCKS server to use.
 o setSocksServer(String, int)
Set's the SOCKS server to use.
 o setSocksServer(String, int, int)
Set's the SOCKS server to use.
 o Trace(String)
Requests a TRACE.
 o Trace(String, NVPair[])
Requests a TRACE.

Variables

 o version
  public final static String version
Current version

Constructors

 o HTTPConnection
  public HTTPConnection(Applet applet) throws ProtocolNotSupportedException
Constructs a connection to the host from where the applet was loaded. Note that current security policies only let applets connect home.
Parameters:
applet - the current applet
 o HTTPConnection
  public HTTPConnection(String host)
Constructs a connection to the specified host on port 80
Parameters:
host - the host
 o HTTPConnection
  public HTTPConnection(String host,
                        int port)
Constructs a connection to the specified host on the specified port
Parameters:
host - the host
port - the port
 o HTTPConnection
  public HTTPConnection(String prot,
                        String host,
                        int port) throws ProtocolNotSupportedException
Constructs a connection to the specified host on the specified port, using the specified protocol (currently only "http" is supported).
Parameters:
prot - the protocol
host - the host
port - the port
Throws: MalformedURLException
if the protocol is not HTTP
 o HTTPConnection
  public HTTPConnection(URL url) throws ProtocolNotSupportedException
Constructs a connection to the host (port) as given in the url.
Parameters:
url - the url
Throws: ProtocolNotSupportedException
if the protocol is not HTTP

Methods

 o Head
  public HTTPResponse Head(String file) throws IOException, AuthTypeNotImplementedException
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
Parameters:
file - the absolute path of the file
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
Get
 o Head
  public HTTPResponse Head(String file,
                           NVPair form_data[]) throws IOException, AuthTypeNotImplementedException
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
Parameters:
file - the absolute path of the file
form_data - an array of Name/Value pairs
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
Get
 o Head
  public HTTPResponse Head(String file,
                           NVPair form_data[],
                           NVPair headers[]) throws IOException, AuthTypeNotImplementedException
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
Parameters:
file - the absolute path of the file
form_data - an array of Name/Value pairs
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
Get
 o Head
  public HTTPResponse Head(String file,
                           String query) throws IOException, AuthTypeNotImplementedException
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
Parameters:
file - the absolute path of the file
query - the query string
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
Get
 o Head
  public HTTPResponse Head(String file,
                           String query,
                           NVPair headers[]) throws IOException, AuthTypeNotImplementedException
Sends the HEAD request. This request is just like the corresponding GET except that it only returns the headers and no data.
Parameters:
file - the absolute path of the file
query - a query
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
Get
 o Get
  public HTTPResponse Get(String file) throws IOException, AuthTypeNotImplementedException
GET's the file.
Parameters:
file - the absolute path of the file
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Get
  public HTTPResponse Get(String file,
                          NVPair form_data[]) throws IOException, AuthTypeNotImplementedException
GET's the file with a query consisting of the specified form-data. The data is urlencoded, turned into a string of the form "name1=value1&name2=value2" and then sent as a query string.
Parameters:
file - the absolute path of the file
form_data - an array of Name/Value pairs
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Get
  public HTTPResponse Get(String file,
                          NVPair form_data[],
                          NVPair headers[]) throws IOException, AuthTypeNotImplementedException
GET's the file with a query consisting of the specified form-data. The data is urlencoded, turned into a string of the form "name1=value1&name2=value2" and then sent as a query string.
Parameters:
file - the absolute path of the file
form_data - an array of Name/Value pairs
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Get
  public HTTPResponse Get(String file,
                          String query) throws IOException, AuthTypeNotImplementedException
GET's the file using the specified query string. The query string is first urlencoded.
Parameters:
file - the absolute path of the file
query - the query
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Get
  public HTTPResponse Get(String file,
                          String query,
                          NVPair headers[]) throws IOException, AuthTypeNotImplementedException
GET's the file using the specified query string. The query string is first urlencoded.
Parameters:
file - the absolute path of the file
query - the query
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Post
  public HTTPResponse Post(String file) throws IOException, AuthTypeNotImplementedException
POST's to the specified file. No data is sent.
Parameters:
file - the absolute path of the file
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Post
  public HTTPResponse Post(String file,
                           NVPair form_data[]) throws IOException, AuthTypeNotImplementedException
POST's form-data to the specified file. The data is first urlencoded and then turned into a string of the form "name1=value1&name2=value2".
Parameters:
file - the absolute path of the file
form_data - an array of Name/Value pairs
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Post
  public HTTPResponse Post(String file,
                           String data) throws IOException, AuthTypeNotImplementedException
POST's the data to the specified file. The data is converted to an array of bytes using the lower byte of each character. The request is sent using the content-type "application/octet-stream".
Parameters:
file - the absolute path of the file
data - the data
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
getBytes
 o Post
  public HTTPResponse Post(String file,
                           String data,
                           NVPair headers[]) throws IOException, AuthTypeNotImplementedException
POST's the data to the specified file using the specified headers.
Parameters:
file - the absolute path of the file
data - the data
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Post
  public HTTPResponse Post(String file,
                           byte data[]) throws IOException, AuthTypeNotImplementedException
POST's the raw data to the specified file. The request is sent using the content-type "application/octet-stream"
Parameters:
file - the absolute path of the file
data - the data
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Post
  public HTTPResponse Post(String file,
                           byte data[],
                           NVPair headers[]) throws IOException, AuthTypeNotImplementedException
POST's the raw data to the specified file using the specified headers.
Parameters:
file - the absolute path of the file
data - the data
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Put
  public HTTPResponse Put(String file,
                          String data) throws IOException, AuthTypeNotImplementedException
PUT's the data into the specified file. The data is converted to an array of bytes using the lower byte of each character. The request ist sent using the content-type "application/octet-stream".
Parameters:
file - the absolute path of the file
data - the data
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
See Also:
getBytes
 o Put
  public HTTPResponse Put(String file,
                          String data,
                          NVPair headers[]) throws IOException, AuthTypeNotImplementedException
PUT's the data into the specified file using the additional headers for the request.
Parameters:
file - the absolute path of the file
data - the data
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Put
  public HTTPResponse Put(String file,
                          byte data[]) throws IOException, AuthTypeNotImplementedException
PUT's the raw data into the specified file. The request is sent using the content-type "application/octet-stream".
Parameters:
file - the absolute path of the file
data - the data
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Put
  public HTTPResponse Put(String file,
                          byte data[],
                          NVPair headers[]) throws IOException, AuthTypeNotImplementedException
PUT's the raw data into the specified file using the additional headers.
Parameters:
file - the absolute path of the file
data - the data
headers - any additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Options
  public HTTPResponse Options(String file,
                              NVPair headers[]) throws IOException, AuthTypeNotImplementedException
Request OPTIONS from the server. If file is "*" then the request applies to the server as a whole; otherwise it applies only to that resource.
Parameters:
file - the absolute path of the resource, or "*"
headers - the headers containing optional info.
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Options
  public HTTPResponse Options(String file) throws IOException, AuthTypeNotImplementedException
Request OPTIONS from the server. If file is "*" then the request applies to the server as a whole; otherwise it applies only to that resource.
Parameters:
file - the absolute path of the resource, or "*"
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Delete
  public HTTPResponse Delete(String file) throws IOException, AuthTypeNotImplementedException
Requests that file be DELETEd from the server.
Parameters:
file - the absolute path of the resource
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Delete
  public HTTPResponse Delete(String file,
                             NVPair headers[]) throws IOException, AuthTypeNotImplementedException
Requests that file be DELETEd from the server.
Parameters:
file - the absolute path of the resource
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Trace
  public HTTPResponse Trace(String file,
                            NVPair headers[]) throws IOException, AuthTypeNotImplementedException
Requests a TRACE. Headers of particular interest here are "Via" and "Max-Forwards".
Parameters:
file - the absolute path of the resource
headers - additional headers
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o Trace
  public HTTPResponse Trace(String file) throws IOException, AuthTypeNotImplementedException
Requests a TRACE.
Parameters:
file - the absolute path of the resource
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o ExtensionMethod
  public HTTPResponse ExtensionMethod(String method,
                                      String file,
                                      byte data[],
                                      NVPair headers[]) throws IOException, AuthTypeNotImplementedException
This is here to allow an arbitrary, non-standard request to be sent. I'm assuming you know what you are doing...
Parameters:
method - the extension method
file - the absolute path of the resource, or null
data - optional data, or null
headers - optional headers, or null
Returns:
a HTTPResponse structure containing the response
Throws: IOException
when an exception is returned from the socket.
Throws: AuthTypeNotImplementedException
when the server requests authorization using a scheme that the authorization handler does not handle.
 o setDefaultHeaders
  public void setDefaultHeaders(NVPair headers[])
Sets the default http headers to be sent with each request. The actual headers sent are determined as follows: for each header specified in multiple places a value given as part of the request takes priority over any default values set by this method, which in turn takes priority over any built-in default values. A different way of looking at it is that we start off with a list of all headers specified with the request, then add any default headers set by this method which aren't already in our list, and finally add any built-in headers which aren't yet in the list. There are two exceptions to this rule: "Content-length", "Host" and "Authorization" headers are always ignored; and when posting form-data any default "Content-type" is ignored in favor of the built-in "application/x-www-form-urlencoded" (however it will be overriden by any content-type header specified as part of the request).

Typical headers you might want to set here are "Accept" and "Connection".

Parameters:
headers - an array of header-name/value pairs (do not give the separating ':').
 o getDefaultHeaders
  public NVPair[] getDefaultHeaders()
Gets the current list of default http headers.
Returns:
an array of header/value pairs.
 o setRawMode
  public void setRawMode(boolean flag)
Sets/Resets raw mode. In raw mode the automatic handling of authorization requests, redirections and certain other response status codes is turned off. The default is false.
Parameters:
flag - if true turns off handling of certain response status codes.
 o addAuthorization
  public void addAuthorization(String scheme,
                               String realm,
                               String cookie,
                               NVPair params[])
Add's an authorization entry to the list. If an entry for the specified scheme and realm already exists then its cookie and params are replaced with the new data.
Parameters:
scheme - the scheme
realm - the realm
cookie - the string used for the "basic" authorization scheme
params - an array of name/value pairs of parameters
 o addBasicAuthorization
  public void addBasicAuthorization(String realm,
                                    String user,
                                    String passw)
Add's an authorization entry for the "basic" authorization scheme to the list. If an entry already exists for the "basic" scheme and the specified realm then it is overwritten.
Parameters:
realm - the realm
user - the username
passw - the password
 o setProxyServer
  public static void setProxyServer(String host,
                                    int port)
Set's the default proxy server to use. The proxy will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables the proxy.

In an application or using the Appletviewer an alternative to this method is to set the following properties (either in the properties file or on the command line): proxySet, proxyHost and proxyPort. Whether proxySet is set to "true" or not determines whether a proxy server is used; if proxySet is "true" then both proxyHost and proxyPort must also be set.

If the proxy server requires authorization and you wish to set this authorization information in the code, then you may use the AuthorizationInfo.addAuthorization() and AuthorizationInfo.addBasicAuthorization() methods to do so. Specify the same host and port as in this method. If you have not given any authorization info and the proxy server requires authorization then you will be prompted for the necessary info via a popup the first time you do a request.

Parameters:
host - the host on which the proxy server resides.
port - the port the proxy server is listening on.
 o setSocksServer
  public static void setSocksServer(String host)
Set's the SOCKS server to use. The server will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables SOCKS.

The code will try to determine the SOCKS version to use at connection time. This might fail for a number of reasons, however, in which case you must specify the version explicitly.

Parameters:
host - the host on which the proxy server resides. The port used is the default port 1080.
See Also:
setSocksServer
 o setSocksServer
  public static void setSocksServer(String host,
                                    int port)
Set's the SOCKS server to use. The server will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables SOCKS.

The code will try to determine the SOCKS version to use at connection time. This might fail for a number of reasons, however, in which case you must specify the version explicitly.

Parameters:
host - the host on which the proxy server resides.
port - the port the proxy server is listening on.
See Also:
setSocksServer
 o setSocksServer
  public static void setSocksServer(String host,
                                    int port,
                                    int version) throws SocksException
Set's the SOCKS server to use. The server will only be used for new HTTPConnections created after this call and will not affect currrent instances of HTTPConnection. A null or empty string host parameter disables SOCKS.

In an application or using the Appletviewer an alternative to this method is to set the following properties (either in the properties file or on the command line): socksHost, socksPort and socksVersion. Whether socksHost is set or not determines whether a SOCKS server is used; if socksPort is not set it defaults to 1080; if socksVersion is not set an attempt will be made to automatically determine the version used by the server.

Note: If you have also set a proxy server then a connection will be made to the SOCKS server, which in turn then makes a connection to the proxy server (possibly via other SOCKS servers), which in turn makes the final connection.

If the proxy server is running SOCKS version 5 and requires username/password authorization, and you wish to set this authorization information in the code, then you may use the AuthorizationInfo.addAuthorization() method to do so. Specify the same host and port as in this method, give the scheme "SOCKS5" and the realm "USER/PASS", set the cookie to null and the params to an array containing a single NVPair in turn containing the username and password. Example:

    NVPair[] up = { new NVPair(username, password) };
    AuthorizationInfo.addAuthorization(host, port, "SOCKS5", "USER/PASS",
                                       null, up);
If you have not given any authorization info and the proxy server requires authorization then you will be prompted for the necessary info via a popup the first time you do a request.
Parameters:
host - the host on which the proxy server resides.
port - the port the proxy server is listening on.
version - the SOCKS version the server is running. Currently this must be '4' or '5'.
Throws: SocksException
If version is not '4' or '5'.

All Packages  Class Hierarchy  This Package  Previous  Next  Index