@Override public void close() throws IOException { HttpPost request = this.request; if (request != null) { request.abort(); } }
@Override public void close() throws IOException { HttpPost request = this.request; if (request != null) { request.abort(); } }
@Override public void abort() { if (method != null && !method.isAborted()) { LOG.info("Forcely aborting current request..."); method.abort(); } }
@Override public void abort() { if (method != null && !method.isAborted()) { LOG.info("Forcely aborting current request..."); method.abort(); } }
if (httpClient != null) { System.out.println("Abort."); httpPost.abort();
log.error("", ex); if (post != null) { post.abort();
/** * 发送body为输入流 * sample */ public static String postBodyAsStream(String url,InputStream inputStream, String encoding) throws Exception{ HttpPost httpPost = new HttpPost(url); HttpEntity body = new InputStreamEntity(inputStream); httpPost.setEntity(body); CloseableHttpResponse response = httpClient.execute(httpPost); try { HttpEntity entity = response.getEntity(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { httpPost.abort(); throw new RuntimeException("HttpClient,error status code :" + statusCode); } String result = null; if (entity != null) { result = EntityUtils.toString(entity, encoding); } EntityUtils.consume(entity); return result; } finally { response.close(); } }
httpPost.abort(); return result != null ? new JSONObject(result) : null;
/** * 发送body为multipart form * sample */ public static String postBodyAsMultipart(String url,Map<String,ContentBody> contentBodies,String charset) throws Exception{ HttpPost httpPost = new HttpPost(url); MultipartEntityBuilder mb = MultipartEntityBuilder.create(); mb.setCharset(Charset.forName(charset)); for(Map.Entry<String,ContentBody> entry : contentBodies.entrySet()) { mb.addPart(entry.getKey(),entry.getValue()); } httpPost.setEntity(mb.build()); CloseableHttpResponse response = httpClient.execute(httpPost); try { HttpEntity entity = response.getEntity(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { httpPost.abort(); throw new RuntimeException("HttpClient,error status code :" + statusCode); } String result = null; if (entity != null) { result = EntityUtils.toString(entity, "utf-8"); } EntityUtils.consume(entity); return result; } finally { response.close(); } }
int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { httpPost.abort(); throw new RuntimeException("HttpClient,error status code :" + statusCode);
@Override public void close() throws IOException { HttpPost request = this.request; if (request != null) { request.abort(); } }
public void close() throws IOException { HttpPost request = this.request; if (request != null) { request.abort(); } }
@Override public void close() throws IOException { HttpPost request = this.request; if (request != null) { request.abort(); } }
/** * Abort the client transmission and response processing. */ public void abort() { if (post != null) { post.abort(); toThrow = new BOSHException("HTTP request aborted"); } }
public void abort() { try { if (httpClient != null) { Log.i(TAG, "Abort."); httpPost.abort(); } } catch (Throwable e) { Log.e(TAG, "Failed to abort", e); } }