String encoding = Base64Encoder.encode ("test1:test1"); HttpPost httppost = new HttpPost("http://host:post/test/login"); httppost.setHeader("Authorization", "Basic " + encoding); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity();
method.setEntity(requestEntity); if (!Thread.currentThread().isInterrupted()) { LOG.debug("Executing request {}", method.getRequestLine()); CloseableHttpResponse response = httpClient.execute(method); try {
System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity();
@Override public byte[] executeHttpRequest(String uri, LinkedHashMap<String, byte[]> entity, boolean verifyResponse) throws Exception { //NOSONAR byte[] responseDataRaw = null; method = new HttpPost(url + uri); MultipartEntity requestEntity = new MultipartEntity(); for (String key : entity.keySet()) { requestEntity.addPart(key, new ByteArrayBody(entity.get(key), null)); } method.setEntity(requestEntity); if (!Thread.currentThread().isInterrupted()) { LOG.debug("Executing request {}", method.getRequestLine()); HttpResponse response = httpClient.execute(method); try { LOG.debug("Received {}", response.getStatusLine()); int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { responseDataRaw = getResponseBody(response, verifyResponse); } else { throw new TransportException(status); } } finally { method = null; } } else { method = null; throw new InterruptedException(); } return responseDataRaw; }
System.out.println( "executing request " + httppost.getRequestLine( ) ); HttpResponse response = httpclient.execute( httppost ); HttpEntity resEntity = response.getEntity( );
System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity();
HttpPost httpPost = new HttpPost("http://host:port/test/login"); String encoding = Base64Encoder.encode ("your_user:your_password"); httpPost.setHeader("Authorization", "Basic " + encoding); String proxyEncoding = Base64Encoder.encode ("proxy_user:proxy_password"); httpPost.setHeader("Proxy-Authorization", "Basic " + proxyEncoding); System.out.println("executing request " + httpPost.getRequestLine()); HttpResponse response = httpClient.execute(httpPost);
String encoding = Base64Encoder.encode ("your_login:your_password"); HttpPost httppost = new HttpPost("http://host:post/test/login"); httppost.setHeader("Authorization", "Basic " + encoding); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity();
HttpClient httpClient = HttpClientBuilder.create().build(); String responseString = null; try { HttpPost request = new HttpPost(link); log.info("Executing request " + request.getRequestLine()); StringEntity content = new StringEntity(data); content.setContentType("application/json"); //or request.setHeader("Content-type", "application/json"); request.setEntity(content); HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity(); responseString = EntityUtils.toString(entity, "UTF-8"); } catch (Exception e) { log.info("Exception thrown while executing HTTPPostRequest"); } return responseString;
private static void dumpRequestInfo(HttpPost postReq, Logger log) { log.info("Request method: " + postReq.getMethod()); log.info("Request line: " + postReq.getRequestLine()); Header[] allHeaders = postReq.getAllHeaders(); log.info("POST header count: " + allHeaders.length); for (Header h : allHeaders) { log.info("Header: " + h); } }
public static void dumpRequestInfo(HttpPost postReq, Logger log) { log.info("Request method: " + postReq.getMethod()); log.info("Request line: " + postReq.getRequestLine()); Header[] allHeaders = postReq.getAllHeaders(); log.info("POST header count: " + allHeaders.length); for (Header h : allHeaders) { log.info("Header: " + h); } }
public static void dumpRequestInfo(HttpPost postReq, Logger log) { log.info("Request method: " + postReq.getMethod()); log.info("Request line: " + postReq.getRequestLine()); Header[] allHeaders = postReq.getAllHeaders(); log.info("POST header count: " + allHeaders.length); for (Header h : allHeaders) { log.info("Header: " + h); } }
public static void dumpRequestInfo(HttpPost postReq, Logger log) { log.info("Request method: " + postReq.getMethod()); log.info("Request line: " + postReq.getRequestLine()); Header[] allHeaders = postReq.getAllHeaders(); log.info("POST header count: " + allHeaders.length); for (Header h : allHeaders) { log.info("Header: " + h); } }
File file = new File(Environment.getExternalStorageDirectory(), fileName); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); FileBody filebody = new FileBody(file,ContentType.create(mimeType), file.getName()); MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create(); multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); multipartEntity.addPart("file", filebody); httppost.setEntity(multipartEntity.build()); System.out.println( "executing request " + httppost.getRequestLine( ) ); try { HttpResponse response = httpclient.execute( httppost ); Log.i("response", response.getStatusLine().toString()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager( ).shutdown( );
HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("url"); File file = new File(filepath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity();
public void upload(String filepath) throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("url"); File file = new File(filepath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // check the response and do what is required }
public void upload(String filepath) throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("url"); File file = new File(filepath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // check the response and do what is required }
public void upload(String filepath) throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("url"); File file = new File(filepath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // check the response and do what is required }
public void upload(String filepath) throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("url"); File file = new File(filepath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // check the response and do what is required }
public void upload(String filepath) throws IOException { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("url"); File file = new File(filepath); MultipartEntity mpEntity = new MultipartEntity(); ContentBody cbFile = new FileBody(file, "image/jpeg"); mpEntity.addPart("userfile", cbFile); httppost.setEntity(mpEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // check the response and do what is required }