|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--HTTPClient.HTTPConnection
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(), getText(), and
getInputStream()). Following are some examples.
If this is in an applet you can retrieve files from your server as follows:
try { 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(rsp.getText()); } else data = rsp.getData(); rsp = con.Get("/another_file"); if (rsp.getStatusCode() >= 300) { System.err.println("Received Error: "+rsp.getReasonLine()); System.err.println(rsp.getText()); } else other_data = rsp.getData(); } catch (IOException ioe) { System.err.println(ioe.toString()); } catch (ModuleException me) { System.err.println("Error handling request: " + me.getMessage()); }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):
try { 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(rsp.getText()); } else stream = rsp.getInputStream(); } catch (IOException ioe) { System.err.println(ioe.toString()); } catch (ModuleException me) { System.err.println("Error handling request: " + me.getMessage()); }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:
try { 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(rsp.getText()); } else text = rsp.getText(); } catch (IOException ioe) { System.err.println(ioe.toString()); } catch (ModuleException me) { System.err.println("Error handling request: " + me.getMessage()); }
There are a whole number of methods for each request type; however the general forms are ([...] means that the enclosed is optional):
Field Summary | |
static String |
version
The current version of this package. |
Fields inherited from interface HTTPClient.GlobalConstants |
CD_0,
CD_CHUNKED,
CD_CLOSE,
CD_CONTLEN,
CD_HDRS,
CD_MP_BR,
CD_NONE,
HTTP,
HTTP_1_0,
HTTP_1_1,
HTTP_NG,
HTTPS,
SHTTP |
Fields inherited from interface HTTPClient.HTTPClientModuleConstants |
REQ_CONTINUE,
REQ_NEWCON_RST,
REQ_NEWCON_SND,
REQ_RESPONSE,
REQ_RESTART,
REQ_RETURN,
REQ_SHORTCIRC,
RSP_CONTINUE,
RSP_NEWCON_REQ,
RSP_NEWCON_SND,
RSP_REQUEST,
RSP_RESTART,
RSP_SEND,
RSP_SHORTCIRC |
Constructor Summary | |
HTTPConnection(Applet applet)
Constructs a connection to the host from where the applet was loaded. |
|
HTTPConnection(String host)
Constructs a connection to the specified host on port 80 |
|
HTTPConnection(String host,
int port)
Constructs a connection to the specified host on the specified port |
|
HTTPConnection(String prot,
String host,
int port)
Constructs a connection to the specified host on the specified port, using the specified protocol (currently only "http" is supported). |
|
HTTPConnection(String prot,
String host,
int port,
InetAddress localAddr,
int localPort)
Constructs a connection to the specified host on the specified port, using the specified protocol (currently only "http" is supported), local address, and local port. |
|
HTTPConnection(URI uri)
Constructs a connection to the host (port) as given in the uri. |
|
HTTPConnection(URL url)
Constructs a connection to the host (port) as given in the url. |
Method Summary | |
void |
addBasicAuthorization(String realm,
String user,
String passwd)
Adds an authorization entry for the "basic" authorization scheme to the list. |
static boolean |
addDefaultModule(Class module,
int pos)
Adds a module to the default list. |
void |
addDigestAuthorization(String realm,
String user,
String passwd)
Adds an authorization entry for the "digest" authorization scheme to the list. |
boolean |
addModule(Class module,
int pos)
Adds a module to the current list. |
HTTPResponse |
Delete(String file)
Requests that file be DELETEd from the server. |
HTTPResponse |
Delete(String file,
NVPair[] headers)
Requests that file be DELETEd from the server. |
static void |
dontProxyFor(String host)
Add host to the list of hosts which should be accessed directly, not via any proxy set by setProxyServer() . |
static void |
dontProxyFor(String[] hosts)
Convenience method to add a number of hosts at once. |
static boolean |
doProxyFor(String host)
Remove host from the list of hosts for which the proxy should not be used. |
HTTPResponse |
ExtensionMethod(String method,
String file,
byte[] data,
NVPair[] headers)
This is here to allow an arbitrary, non-standard request to be sent. |
HTTPResponse |
ExtensionMethod(String method,
String file,
HttpOutputStream os,
NVPair[] headers)
This is here to allow an arbitrary, non-standard request to be sent. |
HTTPResponse |
Get(String file)
GETs the file. |
HTTPResponse |
Get(String file,
NVPair[] form_data)
GETs the file with a query consisting of the specified form-data. |
HTTPResponse |
Get(String file,
NVPair[] form_data,
NVPair[] headers)
GETs the file with a query consisting of the specified form-data. |
HTTPResponse |
Get(String file,
String query)
GETs the file using the specified query string. |
HTTPResponse |
Get(String file,
String query,
NVPair[] headers)
GETs the file using the specified query string. |
boolean |
getAllowUserInteraction()
returns whether modules are allowed to prompt or popup dialogs if neccessary. |
Object |
getContext()
Returns the current context. |
static boolean |
getDefaultAllowUserInteraction()
Gets the default allow-user-action. |
static Object |
getDefaultContext()
Returns the default context. |
NVPair[] |
getDefaultHeaders()
Gets the current list of default http headers. |
static Class[] |
getDefaultModules()
Returns the default list of modules. |
static int |
getDefaultTimeout()
Gets the default timeout value to be used for each new HTTPConnection. |
String |
getHost()
Returns the host this connection is talking to. |
Class[] |
getModules()
Returns the list of modules used currently. |
int |
getPort()
Returns the port this connection connects to. |
String |
getProtocol()
Returns the protocol this connection is talking. |
String |
getProxyHost()
Returns the host of the proxy this connection is using. |
int |
getProxyPort()
Returns the port of the proxy this connection is using. |
int |
getTimeout()
Gets the timeout used for reading response data. |
HTTPResponse |
Head(String file)
Sends the HEAD request. |
HTTPResponse |
Head(String file,
NVPair[] form_data)
Sends the HEAD request. |
HTTPResponse |
Head(String file,
NVPair[] form_data,
NVPair[] headers)
Sends the HEAD request. |
HTTPResponse |
Head(String file,
String query)
Sends the HEAD request. |
HTTPResponse |
Head(String file,
String query,
NVPair[] headers)
Sends the HEAD request. |
boolean |
isCompatibleWith(URI uri)
See if the given uri is compatible with this connection. |
HTTPResponse |
Options(String file)
Request OPTIONS from the server. |
HTTPResponse |
Options(String file,
NVPair[] headers)
Request OPTIONS from the server. |
HTTPResponse |
Options(String file,
NVPair[] headers,
byte[] data)
Request OPTIONS from the server. |
HTTPResponse |
Options(String file,
NVPair[] headers,
HttpOutputStream stream)
Request OPTIONS from the server. |
HTTPResponse |
Post(String file)
POSTs to the specified file. |
HTTPResponse |
Post(String file,
byte[] data)
POSTs the raw data to the specified file. |
HTTPResponse |
Post(String file,
byte[] data,
NVPair[] headers)
POSTs the raw data to the specified file using the specified headers. |
HTTPResponse |
Post(String file,
HttpOutputStream stream)
POSTs the data written to the output stream to the specified file. |
HTTPResponse |
Post(String file,
HttpOutputStream stream,
NVPair[] headers)
POSTs the data written to the output stream to the specified file using the specified headers. |
HTTPResponse |
Post(String file,
NVPair[] form_data)
POSTs form-data to the specified file. |
HTTPResponse |
Post(String file,
NVPair[] form_data,
NVPair[] headers)
POST's form-data to the specified file using the specified headers. |
HTTPResponse |
Post(String file,
String data)
POSTs the data to the specified file. |
HTTPResponse |
Post(String file,
String data,
NVPair[] headers)
POSTs the data to the specified file using the specified headers. |
HTTPResponse |
Put(String file,
byte[] data)
PUTs the raw data into the specified file. |
HTTPResponse |
Put(String file,
byte[] data,
NVPair[] headers)
PUTs the raw data into the specified file using the additional headers. |
HTTPResponse |
Put(String file,
HttpOutputStream stream)
PUTs the data written to the output stream into the specified file. |
HTTPResponse |
Put(String file,
HttpOutputStream stream,
NVPair[] headers)
PUTs the data written to the output stream into the specified file using the additional headers. |
HTTPResponse |
Put(String file,
String data)
PUTs the data into the specified file. |
HTTPResponse |
Put(String file,
String data,
NVPair[] headers)
PUTs the data into the specified file using the additional headers for the request. |
static boolean |
removeDefaultModule(Class module)
Removes a module from the default list. |
boolean |
removeModule(Class module)
Removes a module from the current list. |
void |
setAllowUserInteraction(boolean allow)
Controls whether modules are allowed to prompt the user or pop up dialogs if neccessary. |
void |
setContext(Object context)
Sets the current context. |
void |
setCurrentProxy(String host,
int port)
Sets the proxy used by this instance. |
static void |
setDefaultAllowUserInteraction(boolean allow)
Sets the default allow-user-action. |
void |
setDefaultHeaders(NVPair[] headers)
Sets the default http headers to be sent with each request. |
static void |
setDefaultTimeout(int time)
Sets the default timeout value to be used for each new HTTPConnection. |
static void |
setProxyServer(String host,
int port)
Sets the default proxy server to use. |
void |
setRawMode(boolean raw)
Deprecated. This is not really needed anymore; in V0.2 request were synchronous and therefore to do pipelining you needed to disable the processing of responses. |
static void |
setSocksServer(String host)
Sets the SOCKS server to use. |
static void |
setSocksServer(String host,
int port)
Sets the SOCKS server to use. |
static void |
setSocksServer(String host,
int port,
int version)
Sets the SOCKS server to use. |
void |
setTimeout(int time)
Sets the timeout to be used for creating connections and reading responses. |
protected HTTPResponse |
setupRequest(String method,
String resource,
NVPair[] headers,
byte[] entity,
HttpOutputStream stream)
Sets up the request, creating the list of headers to send and creating instances of the modules. |
void |
stop()
Aborts all the requests currently in progress on this connection and closes all associated sockets. |
String |
toString()
Generates a string of the form protocol://host.domain:port . |
HTTPResponse |
Trace(String file)
Requests a TRACE. |
HTTPResponse |
Trace(String file,
NVPair[] headers)
Requests a TRACE. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final String version
Constructor Detail |
public HTTPConnection(Applet applet) throws ProtocolNotSuppException
applet
- the current appletpublic HTTPConnection(String host)
host
- the hostpublic HTTPConnection(String host, int port)
host
- the hostport
- the portpublic HTTPConnection(String prot, String host, int port) throws ProtocolNotSuppException
prot
- the protocolhost
- the hostport
- the port, or -1 for the default portpublic HTTPConnection(String prot, String host, int port, InetAddress localAddr, int localPort) throws ProtocolNotSuppException
prot
- the protocolhost
- the hostport
- the port, or -1 for the default portlocalAddr
- the local address to bind tolcoalPort
- the local port to bind topublic HTTPConnection(URL url) throws ProtocolNotSuppException
url
- the urlpublic HTTPConnection(URI uri) throws ProtocolNotSuppException
uri
- the uriMethod Detail |
public HTTPResponse Head(String file) throws IOException, ModuleException
file
- the absolute path of the fileGet(java.lang.String)
public HTTPResponse Head(String file, NVPair[] form_data) throws IOException, ModuleException
file
- the absolute path of the fileform_data
- an array of Name/Value pairsGet(java.lang.String, HTTPClient.NVPair[])
public HTTPResponse Head(String file, NVPair[] form_data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the fileform_data
- an array of Name/Value pairsheaders
- additional headersGet(java.lang.String, HTTPClient.NVPair[], HTTPClient.NVPair[])
public HTTPResponse Head(String file, String query) throws IOException, ModuleException
file
- the absolute path of the filequery
- the query string; it will be urlencodedGet(java.lang.String, java.lang.String)
public HTTPResponse Head(String file, String query, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filequery
- the query string; it will be urlencodedheaders
- additional headersGet(java.lang.String, java.lang.String, HTTPClient.NVPair[])
public HTTPResponse Get(String file) throws IOException, ModuleException
file
- the absolute path of the filepublic HTTPResponse Get(String file, NVPair[] form_data) throws IOException, ModuleException
file
- the absolute path of the fileform_data
- an array of Name/Value pairspublic HTTPResponse Get(String file, NVPair[] form_data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the fileform_data
- an array of Name/Value pairsheaders
- additional headerspublic HTTPResponse Get(String file, String query) throws IOException, ModuleException
file
- the absolute path of the filequery
- the querypublic HTTPResponse Get(String file, String query, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filequery
- the query stringheaders
- additional headerspublic HTTPResponse Post(String file) throws IOException, ModuleException
file
- the absolute path of the filepublic HTTPResponse Post(String file, NVPair[] form_data) throws IOException, ModuleException
file
- the absolute path of the fileform_data
- an array of Name/Value pairspublic HTTPResponse Post(String file, NVPair[] form_data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the fileform_data
- an array of Name/Value pairsheaders
- additional headerspublic HTTPResponse Post(String file, String data) throws IOException, ModuleException
file
- the absolute path of the filedata
- the dataString.getBytes()
public HTTPResponse Post(String file, String data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filedata
- the dataheaders
- additional headersString.getBytes()
public HTTPResponse Post(String file, byte[] data) throws IOException, ModuleException
file
- the absolute path of the filedata
- the datapublic HTTPResponse Post(String file, byte[] data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filedata
- the dataheaders
- additional headerspublic HTTPResponse Post(String file, HttpOutputStream stream) throws IOException, ModuleException
file
- the absolute path of the filestream
- the output stream on which the data is writtenpublic HTTPResponse Post(String file, HttpOutputStream stream, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filestream
- the output stream on which the data is writtenheaders
- additional headerspublic HTTPResponse Put(String file, String data) throws IOException, ModuleException
file
- the absolute path of the filedata
- the dataString.getBytes()
public HTTPResponse Put(String file, String data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filedata
- the dataheaders
- additional headersString.getBytes()
public HTTPResponse Put(String file, byte[] data) throws IOException, ModuleException
file
- the absolute path of the filedata
- the datapublic HTTPResponse Put(String file, byte[] data, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filedata
- the dataheaders
- any additional headerspublic HTTPResponse Put(String file, HttpOutputStream stream) throws IOException, ModuleException
file
- the absolute path of the filestream
- the output stream on which the data is writtenpublic HTTPResponse Put(String file, HttpOutputStream stream, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the filestream
- the output stream on which the data is writtenheaders
- any additional headerspublic HTTPResponse Options(String file) throws IOException, ModuleException
file
- the absolute path of the resource, or "*"public HTTPResponse Options(String file, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the resource, or "*"headers
- the headers containing optional info.public HTTPResponse Options(String file, NVPair[] headers, byte[] data) throws IOException, ModuleException
file
- the absolute path of the resource, or "*"headers
- the headers containing optional info.data
- any data to be sent in the optional bodypublic HTTPResponse Options(String file, NVPair[] headers, HttpOutputStream stream) throws IOException, ModuleException
file
- the absolute path of the resource, or "*"headers
- the headers containing optional info.stream
- an output stream for sending the optional bodypublic HTTPResponse Delete(String file) throws IOException, ModuleException
file
- the absolute path of the resourcepublic HTTPResponse Delete(String file, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the resourceheaders
- additional headerspublic HTTPResponse Trace(String file, NVPair[] headers) throws IOException, ModuleException
file
- the absolute path of the resourceheaders
- additional headerspublic HTTPResponse Trace(String file) throws IOException, ModuleException
file
- the absolute path of the resourcepublic HTTPResponse ExtensionMethod(String method, String file, byte[] data, NVPair[] headers) throws IOException, ModuleException
method
- the extension methodfile
- the absolute path of the resource, or nulldata
- optional data, or nullheaders
- optional headers, or nullpublic HTTPResponse ExtensionMethod(String method, String file, HttpOutputStream os, NVPair[] headers) throws IOException, ModuleException
method
- the extension methodfile
- the absolute path of the resource, or nullstream
- optional output stream, or nullheaders
- optional headers, or nullpublic void stop()
Note: there is a small window where a request method such as
Get()
may have been invoked but the request has not
been built and added to the list. Any request in this window will
not be aborted.
public void setDefaultHeaders(NVPair[] headers)
Typical headers you might want to set here are "Accept" and its "Accept-*" relatives, "Connection", "From", "User-Agent", etc.
headers
- an array of header-name/value pairs (do not give the
separating ':').public NVPair[] getDefaultHeaders()
public String getProtocol()
public String getHost()
public int getPort()
public String getProxyHost()
public int getProxyPort()
public boolean isCompatibleWith(URI uri)
uri
- the URI to checkpublic void setRawMode(boolean raw)
The default is false.
raw
- if true removes all modules (except for the retry module)removeModule(java.lang.Class)
public static void setDefaultTimeout(int time)
time
- the timeout in milliseconds.setTimeout(int)
public static int getDefaultTimeout()
setTimeout(int)
public void setTimeout(int time)
resp.getInputStream().close()
should be
invoked.
When creating new sockets the timeout will limit the time spent doing the host name translation and establishing the connection with the server.
The timeout also influences the reading of the response headers. However, it does not specify a how long, for example, getStatusCode() may take, as might be assumed. Instead it specifies how long a read on the socket may take. If the response dribbles in slowly with packets arriving quicker than the timeout then the method will complete normally. I.e. the exception is only thrown if nothing arrives on the socket for the specified time. Furthermore, the timeout only influences the reading of the headers, not the reading of the body.
Read Timeouts are associated with responses, so that you may change this value before each request and it won't affect the reading of responses to previous requests.
time
- the time in milliseconds. A time of 0 means wait
indefinitely.stop()
public int getTimeout()
setTimeout(int)
public void setAllowUserInteraction(boolean allow)
allow
- if true allows modules to interact with user.public boolean getAllowUserInteraction()
public static void setDefaultAllowUserInteraction(boolean allow)
allow
- if true allows modules to interact with user.public static boolean getDefaultAllowUserInteraction()
public static Class[] getDefaultModules()
public static boolean addDefaultModule(Class module, int pos)
Example:
HTTPConnection.addDefaultModule(Class.forName("HTTPClient.CookieModule"), 1);adds the cookie module as the second module in the list.
The default list is created at class initialization time from the property HTTPClient.Modules. This must contain a "|" separated list of classes in the order they're to be invoked. If this property is not set it defaults to: "HTTPClient.RetryModule | HTTPClient.CookieModule | HTTPClient.RedirectionModule | HTTPClient.AuthorizationModule | HTTPClient.DefaultModule | HTTPClient.TransferEncodingModule | HTTPClient.ContentMD5Module | HTTPClient.ContentEncodingModule"
module
- the module's Class objectpos
- the position of this module in the list; if pos
>= 0 then this is the absolute position in the list (0 is
the first position); if pos < 0 then this is
the position relative to the end of the list (-1 means
the last element, -2 the second to last element, etc).HTTPClientModule
public static boolean removeDefaultModule(Class module)
module
- the module's Class objectpublic Class[] getModules()
public boolean addModule(Class module, int pos)
module
- the module's Class objectpos
- the position of this module in the list; if pos
>= 0 then this is the absolute position in the list (0 is
the first position); if pos < 0 then this is
the position relative to the end of the list (-1 means
the last element, -2 the second to last element, etc).HTTPClientModule
public boolean removeModule(Class module)
module
- the module's Class objectpublic void setContext(Object context)
The context may be any object. Contexts are considered equal
if equals()
returns true. Examples of useful context
objects are threads (e.g. if you are running multiple clients, one
per thread) and sockets (e.g. if you are implementing a gateway).
When a new HTTPConnection is created it is initialized with a default context which is the same for all instances. This method must be invoked immediately after a new HTTPConnection is created and before any request method is invoked. Furthermore, this method may only be called once (i.e. the context is "sticky").
context
- the new context; must be non-nullpublic Object getContext()
setContext()
hasn't been invokedsetContext(java.lang.Object)
public static Object getDefaultContext()
setContext(java.lang.Object)
public void addDigestAuthorization(String realm, String user, String passwd)
This is a convenience method and just invokes the corresponding method in AuthorizationInfo.
realm
- the realmuser
- the usernamepassw
- the passwordAuthorizationInfo.addDigestAuthorization(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String)
public void addBasicAuthorization(String realm, String user, String passwd)
This is a convenience method and just invokes the corresponding method in AuthorizationInfo.
realm
- the realmuser
- the usernamepassw
- the passwordAuthorizationInfo.addBasicAuthorization(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String)
public static void setProxyServer(String host, int port)
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): http.proxyHost and http.proxyPort. Whether http.proxyHost is set or not determines whether a proxy server is used.
If the proxy server requires authorization and you wish to set this authorization information in the code, then you may use any of the AuthorizationInfo.addXXXAuthorization() 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.
host
- the host on which the proxy server resides.port
- the port the proxy server is listening on.setCurrentProxy(java.lang.String, int)
public void setCurrentProxy(String host, int port)
Note that if you set a proxy for the connection using this method, and a request made over this connection is redirected to a different server, then the connection used for new server will not pick this proxy setting, but instead will use the default proxy settings.
host
- the host the proxy runs onport
- the port the proxy is listening onsetProxyServer(java.lang.String, int)
public static void dontProxyFor(String host) throws ParseException
setProxyServer()
.
The host may be any of:
The two properties HTTPClient.nonProxyHosts and http.nonProxyHosts are used when this class is loaded to initialize the list of non-proxy hosts. The second property is only read if the first one is not set; the second property is also used the JDK's URLConnection. These properties must contain a "|" separated list of entries which conform to the above rules for the host parameter (e.g. "11.22.33.44|.disney.com").
host
- a host name, domain name, IP-address or IP-subnet.public static void dontProxyFor(String[] hosts)
hosts
- The list of hosts to setdontProxyFor(java.lang.String)
public static boolean doProxyFor(String host) throws ParseException
dontProxyFor()
uses, i.e. this is used to undo a
dontProxyFor()
setting. The syntax for host is
specified in dontProxyFor()
.host
- a host name, domain name, IP-address or IP-subnet.dontProxyFor(java.lang.String)
public static void setSocksServer(String host)
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.
host
- the host on which the proxy server resides. The port
used is the default port 1080.setSocksServer(java.lang.String, int, int)
public static void setSocksServer(String host, int port)
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.
host
- the host on which the proxy server resides.port
- the port the proxy server is listening on.setSocksServer(java.lang.String, int, int)
public static void setSocksServer(String host, int port, int version) throws SocksException
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): HTTPClient.socksHost, HTTPClient.socksPort and HTTPClient.socksVersion. Whether HTTPClient.socksHost is set or not determines whether a SOCKS server is used; if HTTPClient.socksPort is not set it defaults to 1080; if HTTPClient.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.
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'.protected final HTTPResponse setupRequest(String method, String resource, NVPair[] headers, byte[] entity, HttpOutputStream stream) throws IOException, ModuleException
method
- GET, POST, etc.resource
- the resourceheaders
- an array of headers to be usedentity
- the entity (or null)stream
- the output stream (or null) - only one of stream and
entity may be non-nullpublic String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |