ProxyData proxy=task.getProxyData();
if(!ProxyDataImpl.isValid(proxy) && config.isProxyEnableFor(task.getUrl().getHost())) {
proxy=config.getProxyData();
}
HTTPResponse rsp=null;
// execute
try {
rsp = HTTPEngine.get(new URL(url), user, pass, task.getTimeout(),HTTPEngine.MAX_REDIRECT, charset, null, proxy, headers);
} catch (Exception e) {
if(log!=null)log.error(logName,e.getMessage());
hasError=true;
}
// write file
Resource file = task.getResource();
if(!hasError && file!=null && task.isPublish()) {
String n=file.getName();
if(n.indexOf("{id}")!=-1){
n=StringUtil.replace(n, "{id}",CreateUUID.invoke(), false);
file=file.getParentResource().getRealResource(n);
}
if(isText(rsp) && task.isResolveURL()) {
String str;
try {
InputStream stream = rsp.getContentAsStream();
str = stream==null?"":IOUtil.toString(stream,(Charset)null);
if(str==null)str="";
}
catch (IOException e) {
str=e.getMessage();
}
try {
str=new URLResolver().transform(str,task.getUrl(),false);
} catch (PageException e) {
if(log!=null)log.error(logName,e.getMessage());
hasError=true;
}
try {
IOUtil.write(file,str,charset,false);
}
catch (IOException e) {
if(log!=null)log.error(logName,e.getMessage());
hasError=true;
}
}
else {
//print.out("1111111111111111111111111111111");
try {
IOUtil.copy(
rsp.getContentAsStream(),
file,
true
);
//new File(file.getAbsolutePath()).write(method.getResponseBodyAsStream());
}