List of usage examples for org.apache.http.entity.mime HttpMultipartMode BROWSER_COMPATIBLE
HttpMultipartMode BROWSER_COMPATIBLE
To view the source code for org.apache.http.entity.mime HttpMultipartMode BROWSER_COMPATIBLE.
Click Source Link
From source file:com.revo.deployr.client.call.repository.RepositoryFileUploadCall.java
/** * Internal use only, to execute call use RClient.execute(). *///from w w w .j av a 2 s.c om public RCoreResult call() { RCoreResultImpl pResult = null; try { HttpPost httpPost = new HttpPost(serverUrl + API); super.httpUriRequest = httpPost; List<NameValuePair> postParams = new ArrayList<NameValuePair>(); postParams.add(new BasicNameValuePair("format", "json")); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("file", new InputStreamBody(((InputStream) fileStream), "application/zip")); if (options.filename != null) entity.addPart("filename", new StringBody(options.filename, "text/plain", Charset.forName("UTF-8"))); if (options.directory != null) entity.addPart("directory", new StringBody(options.directory, "text/plain", Charset.forName("UTF-8"))); if (options.descr != null) entity.addPart("descr", new StringBody(options.descr, "text/plain", Charset.forName("UTF-8"))); entity.addPart("newversion", new StringBody(Boolean.toString(options.newversion), "text/plain", Charset.forName("UTF-8"))); if (options.newversionmsg != null) entity.addPart("newversionmsg", new StringBody(options.newversionmsg, "text/plain", Charset.forName("UTF-8"))); if (options.restricted != null) entity.addPart("restricted", new StringBody(options.restricted, "text/plain", Charset.forName("UTF-8"))); entity.addPart("shared", new StringBody(Boolean.toString(options.shared), "text/plain", Charset.forName("UTF-8"))); entity.addPart("published", new StringBody(Boolean.toString(options.published), "text/plain", Charset.forName("UTF-8"))); if (options.inputs != null) entity.addPart("inputs", new StringBody(options.inputs, "text/plain", Charset.forName("UTF-8"))); if (options.outputs != null) entity.addPart("outputs", new StringBody(options.outputs, "text/plain", Charset.forName("UTF-8"))); entity.addPart("format", new StringBody("json", "text/plain", Charset.forName("UTF-8"))); httpPost.setEntity(entity); // set any custom headers on the request for (Map.Entry<String, String> entry : httpHeaders.entrySet()) { httpPost.addHeader(entry.getKey(), entry.getValue()); } HttpResponse response = httpClient.execute(httpPost); StatusLine statusLine = response.getStatusLine(); HttpEntity responseEntity = response.getEntity(); String markup = EntityUtils.toString(responseEntity); pResult = new RCoreResultImpl(response.getAllHeaders()); pResult.parseMarkup(markup, API, statusLine.getStatusCode(), statusLine.getReasonPhrase()); } catch (UnsupportedEncodingException ueex) { log.warn("RepositoryFileUploadCall: unsupported encoding exception.", ueex); } catch (IOException ioex) { log.warn("RepositoryFileUploadCall: io exception.", ioex); } return pResult; }
From source file:com.revo.deployr.client.call.repository.RepositoryDirectoryUploadCall.java
/** * Internal use only, to execute call use RClient.execute(). *///from w w w . ja v a2 s.com public RCoreResult call() { RCoreResultImpl pResult = null; try { HttpPost httpPost = new HttpPost(serverUrl + API); super.httpUriRequest = httpPost; List<NameValuePair> postParams = new ArrayList<NameValuePair>(); postParams.add(new BasicNameValuePair("format", "json")); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("file", new InputStreamBody(((InputStream) zipStream), "application/zip")); if (options.directory != null) entity.addPart("directory", new StringBody(options.directory, "text/plain", Charset.forName("UTF-8"))); if (options.descr != null) entity.addPart("descr", new StringBody(options.descr, "text/plain", Charset.forName("UTF-8"))); entity.addPart("newversion", new StringBody(Boolean.toString(options.newversion), "text/plain", Charset.forName("UTF-8"))); if (options.restricted != null) entity.addPart("restricted", new StringBody(options.restricted, "text/plain", Charset.forName("UTF-8"))); entity.addPart("shared", new StringBody(Boolean.toString(options.shared), "text/plain", Charset.forName("UTF-8"))); entity.addPart("published", new StringBody(Boolean.toString(options.published), "text/plain", Charset.forName("UTF-8"))); if (options.inputs != null) entity.addPart("inputs", new StringBody(options.inputs, "text/plain", Charset.forName("UTF-8"))); if (options.outputs != null) entity.addPart("outputs", new StringBody(options.outputs, "text/plain", Charset.forName("UTF-8"))); entity.addPart("format", new StringBody("json", "text/plain", Charset.forName("UTF-8"))); httpPost.setEntity(entity); // set any custom headers on the request for (Map.Entry<String, String> entry : httpHeaders.entrySet()) { httpPost.addHeader(entry.getKey(), entry.getValue()); } HttpResponse response = httpClient.execute(httpPost); StatusLine statusLine = response.getStatusLine(); HttpEntity responseEntity = response.getEntity(); String markup = EntityUtils.toString(responseEntity); pResult = new RCoreResultImpl(response.getAllHeaders()); pResult.parseMarkup(markup, API, statusLine.getStatusCode(), statusLine.getReasonPhrase()); } catch (UnsupportedEncodingException ueex) { log.warn("RepositoryDirectoryUploadCall: unsupported encoding exception.", ueex); } catch (IOException ioex) { log.warn("RepositoryDirectoryUploadCall: io exception.", ioex); } return pResult; }
From source file:key.access.manager.HttpHandler.java
public boolean sendImage(String url, String employeeId, File imageFile) throws IOException { String userHome = System.getProperty("user.home"); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httpPost = new HttpPost(url); FileBody fileBody = new FileBody(imageFile); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("fileToUpload", fileBody); reqEntity.addPart("employee_id", new StringBody(employeeId)); httpPost.setEntity(reqEntity);//from w ww .j a v a 2 s . c om // execute HTTP post request HttpResponse response = httpClient.execute(httpPost); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { String responseStr = EntityUtils.toString(resEntity).trim(); System.out.println(responseStr); return true; } else { return false; } }
From source file:com.revo.deployr.client.call.project.ProjectDirectoryUploadCall.java
/** * Internal use only, to execute call use RClient.execute(). *///from www . j a va 2 s . com public RCoreResult call() { RCoreResultImpl pResult = null; try { HttpPost httpPost = new HttpPost(serverUrl + API); super.httpUriRequest = httpPost; List<NameValuePair> postParams = new ArrayList<NameValuePair>(); postParams.add(new BasicNameValuePair("format", "json")); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("file", new InputStreamBody(((InputStream) fileStream), "application/zip")); entity.addPart("project", new StringBody(project, "text/plain", Charset.forName("UTF-8"))); entity.addPart("filename", new StringBody(options.filename, "text/plain", Charset.forName("UTF-8"))); if (options.descr != null) entity.addPart("descr", new StringBody(options.descr, "text/plain", Charset.forName("UTF-8"))); entity.addPart("overwrite", new StringBody(Boolean.toString(options.overwrite), "text/plain", Charset.forName("UTF-8"))); entity.addPart("format", new StringBody("json", "text/plain", Charset.forName("UTF-8"))); httpPost.setEntity(entity); // set any custom headers on the request for (Map.Entry<String, String> entry : httpHeaders.entrySet()) { httpPost.addHeader(entry.getKey(), entry.getValue()); } HttpResponse response = httpClient.execute(httpPost); StatusLine statusLine = response.getStatusLine(); HttpEntity responseEntity = response.getEntity(); String markup = EntityUtils.toString(responseEntity); pResult = new RCoreResultImpl(response.getAllHeaders()); pResult.parseMarkup(markup, API, statusLine.getStatusCode(), statusLine.getReasonPhrase()); } catch (UnsupportedEncodingException ueex) { log.warn("ProjectDirectoryUploadCall: unsupported encoding exception.", ueex); } catch (IOException ioex) { log.warn("ProjectDirectoryUploadCall: io exception.", ioex); } return pResult; }
From source file:org.zywx.wbpalmstar.platform.push.report.PushReportHttpClient.java
public static String sendPostData(String data, String url, Context mCtx) { // HttpUriRequest httpRequest = new HttpPost(url); PushReportUtility.log("url = " + url); HttpPost post = new HttpPost(url); HttpClient httpClient = getSSLHttpClient(mCtx); // Post???NameValuePair[] // ???request.getParameter("name") // List<NameValuePair> params = new ArrayList<NameValuePair>(); // params.add(new BasicNameValuePair("name", data)); BDebug.d("debug", "data == " + data); PushReportUtility.log("data == " + data); HttpResponse httpResponse = null; post.setHeader("Accept", "*/*"); // HttpClient httpClient = null; try {/*from ww w .jav a 2s .c o m*/ MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); // ?HTTP request post.setEntity(new ByteArrayEntity(data.getBytes())); // ?HTTP response // httpClient = getSSLHttpClient(); httpResponse = httpClient.execute(post); // ??200 ok int responesCode = httpResponse.getStatusLine().getStatusCode(); BDebug.d("debug", "responesCode == " + responesCode); PushReportUtility.log("responesCode == " + responesCode); if (responesCode == 200) { // ? String res = EntityUtils.toString(httpResponse.getEntity()); PushReportUtility.log("res == " + res); return res; } else { System.out.println(EntityUtils.toString(httpResponse.getEntity())); } } catch (Exception e) { PushReportUtility.log("Exception == " + e.getMessage()); e.printStackTrace(); } finally { if (post != null) { post.abort(); post = null; } if (httpResponse != null) { httpResponse = null; } if (httpClient != null) { httpClient.getConnectionManager().shutdown(); httpClient = null; } } return null; }
From source file:nya.miku.wishmaster.http.ExtendedMultipartBuilder.java
public ExtendedMultipartBuilder() { builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .setBoundary(generateBoundary()); }
From source file:com.app.precared.utils.MultipartEntityBuilder.java
public MultipartEntityBuilder setLaxMode() { this.mode = HttpMultipartMode.BROWSER_COMPATIBLE; return this; }
From source file:com.openmeap.http.FileHandlingHttpRequestExecuterImpl.java
@Override public HttpResponse postData(String url, Hashtable getParams, Hashtable postParams) throws HttpRequestException { // test to determine whether this is a file upload or not. Boolean isFileUpload = false; for (Object o : postParams.values()) { if (o instanceof File) { isFileUpload = true;/*from w w w . j a v a 2s .c o m*/ break; } } if (isFileUpload) { try { HttpPost httpPost = new HttpPost(createUrl(url, getParams)); httpPost.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for (Object o : postParams.entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o; if (entry.getValue() instanceof File) { // For File parameters File file = (File) entry.getValue(); FileNameMap fileNameMap = URLConnection.getFileNameMap(); String type = fileNameMap.getContentTypeFor(file.toURL().toString()); entity.addPart(entry.getKey(), new FileBody(((File) entry.getValue()), type)); } else { // For usual String parameters entity.addPart(entry.getKey(), new StringBody(entry.getValue().toString(), "text/plain", Charset.forName(FormConstants.CHAR_ENC_DEFAULT))); } } httpPost.setEntity(entity); return execute(httpPost); } catch (Exception e) { throw new HttpRequestException(e); } } else { return super.postData(url, getParams, postParams); } }
From source file:com.sytecso.jbpm.client.rs.JbpmRestTemplate.java
private String requestPost(String url, Map<String, Object> parameters, boolean multipart) throws Exception { log.info("--- POST"); MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); List<BasicNameValuePair> formparams = new ArrayList<BasicNameValuePair>(); if (parameters == null) { parameters = new HashMap<String, Object>(); }/*ww w . j a v a 2 s. c o m*/ Set<String> keys = parameters.keySet(); for (String keyString : keys) { String value = parameters.get(keyString).toString(); formparams.add(new BasicNameValuePair(keyString, value)); if (multipart) { try { StringBody stringBody = new StringBody(value, Charset.forName("UTF-8")); //System.out.println(stringBody.); multiPartEntity.addPart(keyString, (ContentBody) stringBody); } catch (Exception e) { throw new RuntimeException(e); } } } HttpPost httpPost = new HttpPost(url); if (multipart) { httpPost.setEntity(multiPartEntity); } else { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");// new UrlEncodedFormEntity(formparams, "multipart/form-data"); //// httpPost.setEntity(entity); } /*if(!this.SESSION_ID.equals("")){ httpPost.setHeader("Cookie", "JSESSIONID="+SESSION_ID); }*/ HttpResponse response = httpClient.execute(httpPost); return read(response.getEntity().getContent()); }
From source file:com.sat.sonata.MenuActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection. switch (item.getItemId()) { case R.id.stop: Log.d("SITTING", "Inside stop case"); //stopService(new Intent(this, SonataService.class)); return true; case R.id.recognise: String imagePath = getIntent().getStringExtra("image"); getIntent().removeExtra("image"); Log.d("SITTING", imagePath); HttpPost postRequest = new HttpPost("http://129.31.195.224:8080/picUpload"); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); try {/*from w ww . j a v a 2 s.co m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); Bitmap bitmap; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; bitmap = BitmapFactory.decodeFile(imagePath, options); bitmap.compress(Bitmap.CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); ByteArrayBody bab = new ByteArrayBody(data, "music.jpg"); reqEntity.addPart("music", bab); postRequest.setEntity(reqEntity); HttpPost[] posts = new HttpPost[1]; posts[0] = postRequest; GetImageTask getImageTask = new GetImageTask(); getImageTask.execute(posts); } catch (Exception e) { Log.v("Exception in Image", "" + e); // reqEntity.addPart("picture", new StringBody("")); } default: return super.onOptionsItemSelected(item); } }