public class HttpTransport extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE |
Constructor and Description |
---|
HttpTransport()
Deprecated.
Replaced by the newInstance() method
|
Modifier and Type | Method and Description |
---|---|
void |
addTextType(String texttype)
Add a MIME type to the list of text types.
|
byte[] |
downloadURL(String url)
Retrieve large response from the URL and returns the data read.
|
String |
dumpResponseHeaders()
Utility class to get responseHeaders as a string.
|
StringBuilder |
fetchPage(String page,
String[] images,
String postRequest)
Makes a POST request, fetches the main page and all other image or
resource pages.
|
StringBuilder |
fetchResponseData(InputStream stream)
Fetches the data from the stream, converts to char, and returns it as
a StringBuilder.
|
StringBuilder |
fetchResponseData(Reader reader)
Fetches the data from the reader and returns it as a StringBuilder.
|
StringBuilder |
fetchURL(String url)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(String url,
Map<String,String> headers)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(String url,
String postRequest)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(String url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(URL url)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(URL url,
Map<String,String> headers)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(URL url,
String postRequest)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(URL url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(URL page,
URL[] images,
String postRequest)
Method not implemented.
|
int |
getContentSize()
Obtains the size of the last read page or resource.
|
org.apache.commons.httpclient.Cookie[] |
getCookies()
Obtains the list of all cookies
|
String[] |
getCookieValuesByName(String name)
Obtains the list of cookie values by the name of the cookies.
|
StringBuilder |
getResponseBuffer()
Obtains the reference of the current response buffer.
|
int |
getResponseCode()
Obtains the response code of the last request.
|
String[] |
getResponseHeader(String name)
Obtains the header fields of the last request's response.
|
boolean |
isFollowRedirects()
Checks whether the connections managed by this transport follows
redirects or not.
|
boolean |
matchResponse(InputStream stream,
String regex)
Matches the regular expression against the data read from the stream.
|
boolean |
matchResponse(Reader reader,
String regex)
Matches the regular expression against the data read from the reader.
|
boolean |
matchResponse(String regex)
Maches the regular expression against the data in the current buffer.
|
boolean |
matchURL(String url,
String regex)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(String url,
String regex,
Map<String,String> headers)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(String url,
String postRequest,
String regex)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
boolean |
matchURL(String url,
String postRequest,
String regex,
Map<String,String> headers)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
boolean |
matchURL(URL url,
String regex)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(URL url,
String regex,
Map<String,String> headers)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(URL url,
String postRequest,
String regex)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
boolean |
matchURL(URL url,
String postRequest,
String regex,
Map<String,String> headers)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
static HttpTransport |
newInstance()
Creates an instance of HttpTransport with a fresh state.
|
int |
readURL(String url)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(String url,
byte[] postRequest)
Makes a POST request to the URL without encoding the data (the
header type is application/octet-stream).
|
int |
readURL(String url,
Map<String,String> headers)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(String url,
String postRequest)
Makes a POST request to the URL.
|
int |
readURL(String url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
int |
readURL(URL url)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(URL url,
byte[] postRequest,
Map<String,String> headers)
Makes a POST request to the URL without encoding the data (the
header type is application/octet-stream).
|
int |
readURL(URL url,
Map<String,String> headers)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(URL url,
String postRequest)
Makes a POST request to the URL.
|
int |
readURL(URL url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
void |
setDownloadSpeed(int kbps)
Set the download speed for this HTTP transport object
|
void |
setFollowRedirects(boolean follow)
Sets the http connections managed by this transport to follow or
not follow HTTP redirects.
|
static void |
setProvider(String newProvider)
Sets the provider class.
|
void |
setUploadSpeed(int kbps)
Set the upload speed for this HTTP transport object
|
public HttpTransport()
public static void setProvider(String newProvider)
newProvider
- The fully qualified name of the provider classpublic static HttpTransport newInstance()
setProvider(java.lang.String)
public void setFollowRedirects(boolean follow)
follow
- True if HTTP redirects should be automatically followed,
false otherwisepublic void addTextType(String texttype)
texttype
- The content type of a HTTP response that contains text.public boolean isFollowRedirects()
public StringBuilder getResponseBuffer()
public int readURL(URL url, Map<String,String> headers) throws IOException
url
- The URL to read fromheaders
- The request headersIOException
public int readURL(URL url) throws IOException
url
- The URL to read fromIOException
public int readURL(String url, Map<String,String> headers) throws IOException
url
- The URL to read fromheaders
- The request headersIOException
public int readURL(String url) throws IOException
url
- The URL to read fromIOException
public int readURL(URL url, String postRequest) throws IOException
url
- The URL to read frompostRequest
- The post request stringIOException
public int readURL(URL url, String postRequest, Map<String,String> headers) throws IOException
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
public int readURL(URL url, byte[] postRequest, Map<String,String> headers) throws IOException
url
- The URL to read frompostRequest
- The binary data to sendheaders
- The request headersIOException
public int readURL(String url, byte[] postRequest) throws IOException
url
- The URL to read frompostRequest
- The binary data to sendIOException
public int readURL(String url, String postRequest) throws IOException
url
- The URL to read frompostRequest
- The post request stringIOException
public int readURL(String url, String postRequest, Map<String,String> headers) throws IOException
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
public StringBuilder fetchURL(URL url, Map<String,String> headers) throws IOException
url
- The URL to read fromheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL url) throws IOException
url
- The URL to read fromIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(String url, Map<String,String> headers) throws IOException
url
- The URL to read fromheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(String url) throws IOException
url
- The URL to read fromIOException
addTextType(String)
,
getContentSize()
public byte[] downloadURL(String url) throws IOException
url
- The URL to read fromIOException
getContentSize()
public StringBuilder fetchURL(String url, String postRequest) throws IOException
url
- The URL to read frompostRequest
- The post request stringIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(String url, String postRequest, Map<String,String> headers) throws IOException
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL url, String postRequest, Map<String,String> headers) throws IOException
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL url, String postRequest) throws IOException
url
- The URL to read frompostRequest
- The post request stringIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL page, URL[] images, String postRequest) throws IOException
page
- The page URLimages
- The image or other resource URLs to fetch with pagepostRequest
- The post stringIOException
- If an I/O error occurredpublic StringBuilder fetchPage(String page, String[] images, String postRequest) throws IOException
page
- The page URLimages
- The image or other resource URLs to fetch with pagepostRequest
- The post stringIOException
- If an I/O error occurredpublic int getContentSize()
public StringBuilder fetchResponseData(InputStream stream) throws IOException
stream
- The stream to read fromIOException
public StringBuilder fetchResponseData(Reader reader) throws IOException
reader
- The reader to read fromIOException
public boolean matchResponse(String regex)
regex
- The regular expression to matchpublic boolean matchResponse(InputStream stream, String regex) throws IOException
stream
- The source of the dataregex
- The regular expression to matchIOException
public boolean matchResponse(Reader reader, String regex) throws IOException
reader
- The source of the dataregex
- The regular expression to matchIOException
public boolean matchURL(String url, String regex) throws IOException
url
- The source of the dataregex
- THe regular expression to matchIOException
public boolean matchURL(String url, String regex, Map<String,String> headers) throws IOException
url
- The source of the dataregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchURL(URL url, String regex) throws IOException
url
- The source of the dataregex
- The regular expression to matchIOException
public boolean matchURL(URL url, String regex, Map<String,String> headers) throws IOException
url
- The source of the dataregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchURL(URL url, String postRequest, String regex) throws IOException
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchIOException
public boolean matchURL(URL url, String postRequest, String regex, Map<String,String> headers) throws IOException
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchURL(String url, String postRequest, String regex) throws IOException
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchIOException
public boolean matchURL(String url, String postRequest, String regex, Map<String,String> headers) throws IOException
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchheaders
- The request headersIOException
public String[] getCookieValuesByName(String name)
name
- The cookie namepublic org.apache.commons.httpclient.Cookie[] getCookies()
public String[] getResponseHeader(String name)
name
- The response header field of interestpublic String dumpResponseHeaders()
public int getResponseCode()
public void setDownloadSpeed(int kbps)
kbps
- desired speed in kilobytes per secondUnsupportedOperationException
- if the underlying HTTP transport
doesn't support bandwidth-metered (throttled) socketspublic void setUploadSpeed(int kbps)
kbps
- desired speed in kilobytes per secondUnsupportedOperationException
- if the underlying HTTP transport
doesn't support bandwidth-metered (throttled) sockets