List of usage examples for org.apache.http.entity.mime.content StringBody StringBody
public StringBody(final String text) throws UnsupportedEncodingException
From source file:cn.clxy.upload.ApacheHCUploader.java
@Override public void done(String fileName, long partCount) { Map<String, ContentBody> params = new HashMap<String, ContentBody>(); try {//from w w w. j a va 2 s.c o m params.put(Config.keyFileName, new StringBody(fileName)); params.put(Config.keyPartCount, new StringBody(String.valueOf(partCount))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } post(params); log.debug(fileName + " notification is done."); }
From source file:com.puppetlabs.geppetto.forge.client.OAuthModule.java
@Override public AuthResponse authenticate(HttpClient httpClient) throws IOException { HttpPost request = new HttpPost(oauthURL); MultipartEntity entity = new MultipartEntity(); entity.addPart("grant_type", new StringBody("password")); entity.addPart("client_id", new StringBody(clientId)); entity.addPart("client_secret", new StringBody(clientSecret)); entity.addPart("username", new StringBody(username)); entity.addPart("password", new StringBody(password)); request.setEntity(entity);//w ww .j ava2 s . c o m return httpClient.execute(request, new JSonResponseHandler<OAuthResponse>(gson, OAuthResponse.class)); }
From source file:cn.clxy.codes.upload.ApacheHCUploader.java
@Override public void done(String fileName, long partCount) { Map<String, ContentBody> params = new HashMap<String, ContentBody>(); try {//www .ja va2s . c o m params.put(Config.KEY_FILE_NAME, new StringBody(fileName)); params.put(Config.PART_COUNT, new StringBody(String.valueOf(partCount))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } post(params); log.debug(fileName + " notification is done."); }
From source file:com.phunkosis.gifstitch.helpers.ShareHelper.java
public static String uploadToSite(String filePath, Context c) { URLStorageHelper storage = new URLStorageHelper(c); String url = storage.lookupUrl(filePath); if (url != null) { return url; }/*from www. ja va2 s. c om*/ String did = GSSettings.getDeviceId(); File file = new File(filePath); String seed = "" + GSS + did + file.getName(); String hash = generateSHA256(seed); HttpClient httpClient = new DefaultHttpClient(); try { HttpPost httpPost = new HttpPost(SHAREURL); FileBody fileBody = new FileBody(file); StringBody didBody = new StringBody(did); StringBody hashBody = new StringBody(hash); StringBody filenameBody = new StringBody(file.getName()); MultipartEntity mpe = new MultipartEntity(); mpe.addPart("did", didBody); mpe.addPart("hash", hashBody); mpe.addPart("img", filenameBody); mpe.addPart("sharedgif", fileBody); httpPost.setEntity(mpe); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader r = new BufferedReader(new InputStreamReader(entity.getContent())); String line = r.readLine(); if (line != null && line.startsWith("http:")) { storage.addRow(filePath, line); return line; } return line; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { httpClient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } return null; }
From source file:com.urucas.services.JSONFileRequest.java
@SuppressWarnings("deprecation") @Override//from w ww .java2s .c o m protected String doInBackground(String... uri) { HttpClient httpclient = new DefaultHttpClient(); // add request params StringBuffer url = new StringBuffer(uri[0]).append("?") .append(URLEncodedUtils.format(getParams(), "UTF-8")); HttpPost _post = new HttpPost(url.toString()); HttpContext localContext = new BasicHttpContext(); Log.i("url ---->", url.toString()); MultipartEntity _entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for (int index = 0; index < getParams().size(); index++) { try { _entity.addPart(getParams().get(index).getName(), new StringBody(getParams().get(index).getValue())); } catch (UnsupportedEncodingException e) { } } _entity.addPart("imagen", new FileBody(file)); _post.setEntity(_entity); HttpResponse response; String responseString = null; // execute try { response = httpclient.execute(_post, localContext); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); if (isCancelled()) { rsh.onError("Task cancel"); } } else { //Closes the connection. response.getEntity().getContent().close(); Log.i("status", String.valueOf(statusLine.getStatusCode())); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { e.printStackTrace(); //rsh.onError(e.getMessage()); } catch (IOException e) { e.printStackTrace(); //rsh.onError(e.getMessage()); } return responseString; }
From source file:com.rogiel.httpchannel.http.PostMultipartRequest.java
@Override public PostMultipartRequest parameter(String name, String value) throws UnsupportedEncodingException { return parameter(name, new StringBody(value)); }
From source file:de.vanita5.twittnuker.util.shortener.TweetShortenerUtils.java
/** * Shorten long tweets with hotot.in//ww w. jav a 2 s. c om * @param context * @param text * @param accounts * @return shortened tweet */ public static String shortWithHototin(final Context context, final String text, final Account[] accounts) { String screen_name = null; String avatar_url = null; if (accounts != null && accounts.length > 0) { screen_name = getAccountScreenName(context, accounts[0].account_id); avatar_url = getAccountProfileImage(context, accounts[0].account_id); avatar_url = avatar_url != null && !avatar_url.isEmpty() ? avatar_url : DEFAULT_AVATAR_URL; } try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(HOTOTIN_URL); MultipartEntity requestEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); requestEntity.addPart(HOTOTIN_ENTITY_NAME, new StringBody(screen_name)); requestEntity.addPart(HOTOTIN_ENTITY_AVATAR, new StringBody(avatar_url)); requestEntity.addPart(HOTOTIN_ENTITY_TEXT, new StringBody(text, Charset.forName("UTF-8"))); httpPost.setEntity(requestEntity); InputStream responseStream; BufferedReader br; HttpResponse response = httpClient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); responseStream = responseEntity.getContent(); br = new BufferedReader(new InputStreamReader(responseStream)); String responseLine = br.readLine(); String tmpResponse = ""; while (responseLine != null) { tmpResponse += responseLine + System.getProperty("line.separator"); responseLine = br.readLine(); } br.close(); JSONObject jsonObject = new JSONObject(tmpResponse); String result = jsonObject.getString("text"); return result; } catch (UnsupportedEncodingException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } catch (ClientProtocolException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } catch (IOException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } catch (JSONException e) { if (Utils.isDebugBuild()) Log.e(LOG_TAG, e.getMessage()); e.printStackTrace(); } return null; }