|
|
|
@ -46,6 +46,17 @@ public class HttpClientDownloader implements Downloader {
|
|
|
|
|
return (Html) page.getHtml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A simple method to download a url.
|
|
|
|
|
*
|
|
|
|
|
* @param url
|
|
|
|
|
* @return html
|
|
|
|
|
*/
|
|
|
|
|
public Html download(String url,String charset) {
|
|
|
|
|
Page page = download(new Request(url), Site.me().setCharset(charset).toTask());
|
|
|
|
|
return (Html) page.getHtml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Page download(Request request, Task task) {
|
|
|
|
|
Site site = null;
|
|
|
|
@ -87,13 +98,12 @@ public class HttpClientDownloader implements Downloader {
|
|
|
|
|
} while (retry);
|
|
|
|
|
int statusCode = httpResponse.getStatusLine().getStatusCode();
|
|
|
|
|
if (acceptStatCode.contains(statusCode)) {
|
|
|
|
|
handleGzip(httpResponse);
|
|
|
|
|
//charset
|
|
|
|
|
if (charset == null) {
|
|
|
|
|
String value = httpResponse.getEntity().getContentType().getValue();
|
|
|
|
|
charset = UrlUtils.getCharset(value);
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
handleGzip(httpResponse);
|
|
|
|
|
return handleResponse(request, charset, httpResponse, task);
|
|
|
|
|
} else {
|
|
|
|
|
logger.warn("code error " + statusCode + "\t" + request.getUrl());
|
|
|
|
|