1. 程式人生 > >httpClient中的cookie失效時間處理

httpClient中的cookie失效時間處理

public static Map<String, Object> doHttpPost(String url, InputStream is, String fileId, CloseableHttpClient httpClient)
throws ClientProtocolException, IOException, Exception {
logger.info("=== begin request, do http post ===>" + url);
Map<String, Object> map = new HashMap<String, 
Object>(); CloseableHttpResponse response = null; HttpEntity entity = null; HttpPost httpPost = null; try { httpPost = new HttpPost(url); HttpEntity reqFile = MultipartEntityBuilder.create() .setContentType(ContentType.MULTIPART_FORM_DATA) .setBoundary("----WebKitFormBoundaryriApLsyI1shPEGEH"
) .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .addBinaryBody("files", is, ContentType.MULTIPART_FORM_DATA, fileId) .build(); httpPost.setEntity(reqFile); response = httpClient.execute(httpPost); logger.info("上傳檔案的respons:" + response.toString()); entity = response.getEntity(); String content = EntityUtils
.toString(entity, "UTF-8"); logger.info("上傳檔案返回Json資訊 : " + content); map.put("content" , content); } catch (Exception e) { logger.info("=== do http post exception ===",e); httpPost.abort(); throw e; } finally { if (entity != null) { try { EntityUtils.consume(entity); } catch (Exception e) { } } } return map; }