DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
DefaultConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, httpHost);
FileEntity fileEntity = null;
if (!file.equals("--end--")) {
log.info("开始传输文件:" + file, true);
fileEntity = new FileEntity(new File(folder + file), "UTF-8");
try {
if (!conn.isOpen()) {
Socket socket = new Socket(httpHost.getHostName(), httpHost.getPort());
conn.bind(socket, params);
}
BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", file);
request.setEntity(fileEntity);
context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
request.setParams(params);
httpexecutor.preProcess(request, httpproc, context);
HttpResponse response = httpexecutor.execute(request, conn, context);
if (!connStrategy.keepAlive(response, context)) {
conn.close();
}
} catch (Exception e) {
log.error(e.getMessage(), true);
} finally {
try {
conn.close();
} catch (Exception e) {
log.error(e.getMessage(), true);
}
log.info("传输文件:" + file + "完毕。", true);
}
} else {
File f = new File("end");
try {
f.createNewFile();
fileEntity = new FileEntity(f, "UTF-8");
} catch (IOException ex) {
}
try {
if (!conn.isOpen()) {
Socket socket = new Socket(httpHost.getHostName(), httpHost.getPort());