List of usage examples for org.apache.http.protocol HTTP UTF_8
String UTF_8
To view the source code for org.apache.http.protocol HTTP UTF_8.
Click Source Link
From source file:com.pursuer.reader.easyrss.network.AbsDataSyncer.java
protected Reader httpPostQueryReader(final AbsURL url) throws DataSyncerException { try {// w ww .j a v a 2 s . c om return new InputStreamReader(httpPostQueryStream(url), HTTP.UTF_8); } catch (final UnsupportedEncodingException exception) { throw new DataSyncerException(exception); } }
From source file:org.hk.jt.client.core.Request.java
private HttpResponse execPost() throws URISyntaxException, InvalidKeyException, UnsupportedEncodingException, NoSuchAlgorithmException, IOException { DefaultHttpClient client = new DefaultHttpClient(); HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.BROWSER_COMPATIBILITY); HttpPost httpPost = new HttpPost(); httpPost.setURI(new URI(requestIf.getUrl())); httpPost.setHeader("Authorization", createAuthorizationValue()); if (postParameter != null && !postParameter.isEmpty()) { final List<NameValuePair> params = new ArrayList<NameValuePair>(); for (String key : postParameter.keySet()) { params.add(new BasicNameValuePair(key, postParameter.get(key))); }//from w w w. j a v a 2s. c o m httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); } if (requestIf.getFiles() != null) { final MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); List<NameValuePair> fileList = requestIf.getFiles(); if (fileList != null && !fileList.isEmpty()) { for (NameValuePair val : fileList) { File file = new File(val.getValue()); entity.addPart(val.getName(), new FileBody(file, CONTENTTYPE_BINARY)); } } httpPost.setEntity(entity); } httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); return client.execute(httpPost); }
From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java
public void uploadTrack(Bundle bundle) { Track track = TracksStore.Track.fromBundle(bundle); //SystemClock.sleep(1500); if (track.getmIdTrack() == 0) { MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(HTTP.UTF_8)); try {// w w w . j a va 2 s. c om if (track.getmTrackPath() != null && !"".equals(track.getmTrackPath())) { ContentBody asset_Data = new FileBody(new File(track.getmTrackPath())); entity.addPart("track[asset_data]", asset_Data); } if (track.getmArtworkPath() != null && !"".equals(track.getmArtworkPath())) { ContentBody artworkData = new FileBody(new File(track.getmArtworkPath())); entity.addPart("track[artwork_data]", artworkData); } if (track.getmTitle() != null && !"".equals(track.getmTitle())) { entity.addPart("track[title]", new StringBody(track.getmTitle())); } if (track.getmDescription() != null && !"".equals(track.getmDescription())) { entity.addPart("track[description]", new StringBody(track.getmDescription())); } if (track.getmDownloadable() != null && !"".equals(track.getmDownloadable())) { entity.addPart("track[downloadable]", new StringBody(track.getmDownloadable())); } if (track.getmSharing() != null && !"".equals(track.getmSharing())) { entity.addPart("track[sharing]", new StringBody(track.getmSharing())); } if (!"".equals(track.getmBpm())) { entity.addPart("track[bpm]", new StringBody(String.valueOf(track.getmBpm()))); } if (track.getmTagList() != null && !"".equals(track.getmTagList())) { entity.addPart("track[tag_list]", new StringBody(track.getmTagList())); } if (track.getmGenre() != null && !"".equals(track.getmGenre())) { entity.addPart("track[genre]", new StringBody(track.getmGenre())); } if (track.getmLicense() != null && !"".equals(track.getmLicense())) { entity.addPart("track[license]", new StringBody(track.getmLicense())); } if (track.getmLabelName() != null && !"".equals(track.getmLabelName())) { entity.addPart("track[label_name]", new StringBody(track.getmLabelName())); } if (track.getmTrackType() != null && !"".equals(track.getmTrackType())) { entity.addPart("track[track_type]", new StringBody(track.getmTrackType())); } HttpPost filePost = new HttpPost("http://api.soundcloud.com/tracks"); Soundroid.getSc().signRequest(filePost); filePost.setEntity(entity); try { //SystemClock.sleep(1000); showNotification("Uploading track " + track.getmTitle()); final HttpResponse response = sClient.execute(filePost); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) { showNotification("Track " + track.getmTitle() + " uploaded"); sClient.getConnectionManager().closeExpiredConnections(); totalUploads--; } } finally { if (entity != null) { entity.consumeContent(); } } } catch (Exception e) { } } else {//Edicin de la cancin MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, Charset.forName(HTTP.UTF_8)); try { if (track.getmTrackPath() != null && !"".equals(track.getmTrackPath())) { ContentBody asset_Data = new FileBody(new File(track.getmTrackPath())); entity.addPart("track[asset_data]", asset_Data); } if (track.getmArtworkPath() != null && !"".equals(track.getmArtworkPath())) { ContentBody artworkData = new FileBody(new File(track.getmArtworkPath())); entity.addPart("track[artwork_data]", artworkData); } if (track.getmTitle() != null) { entity.addPart("track[title]", new StringBody(track.getmTitle())); } if (track.getmDescription() != null) { entity.addPart("track[description]", new StringBody(track.getmDescription())); } if (track.getmDownloadable() != null) { entity.addPart("track[downloadable]", new StringBody(track.getmDownloadable())); } if (track.getmSharing() != null) { entity.addPart("track[sharing]", new StringBody(track.getmSharing())); } entity.addPart("track[bpm]", new StringBody(String.valueOf(track.getmBpm()))); if (track.getmTagList() != null) { entity.addPart("track[tag_list]", new StringBody(track.getmTagList())); } if (track.getmGenre() != null) { entity.addPart("track[genre]", new StringBody(track.getmGenre())); } if (track.getmLicense() != null) { entity.addPart("track[license]", new StringBody(track.getmLicense())); } if (track.getmLabelName() != null) { entity.addPart("track[label_name]", new StringBody(track.getmLabelName())); } if (track.getmTrackType() != null) { entity.addPart("track[track_type]", new StringBody(track.getmTrackType())); } HttpPut filePut = new HttpPut("http://api.soundcloud.com/tracks/" + track.getmIdTrack() + ".json"); Soundroid.getSc().signRequest(filePut); filePut.setEntity(entity); try { //SystemClock.sleep(1000); showNotification("Uploading track " + track.getmTitle()); final HttpResponse response = sClient.execute(filePut); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) { showNotification("Track " + track.getmTitle() + " edited"); sClient.getConnectionManager().closeExpiredConnections(); } } finally { if (entity != null) { entity.consumeContent(); } } } catch (Exception e) { } } }
From source file:de.escidoc.core.test.aa.UserPreferenceTestBase.java
protected String retrievePreference(final String id, final String name) throws Exception { Object result = client.retrievePreference(id, name); String xmlResult = null;// w ww. j a v a2 s.c o m if (result instanceof HttpResponse) { HttpResponse method = (HttpResponse) result; xmlResult = EntityUtils.toString(method.getEntity(), HTTP.UTF_8); assertHttpStatusOfMethod("", method); } else if (result instanceof String) { xmlResult = (String) result; } return xmlResult; }
From source file:uk.bowdlerize.API.java
public String registerUser(String emailAddress, String password) { DefaultHttpClient httpclient = new DefaultHttpClient(); JSONObject json;//from w ww.j av a2 s. co m HttpPost httpost = new HttpPost("https://api.blocked.org.uk/1.2/register/user"); httpost.setHeader("Accept", "application/json"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("email", emailAddress)); nvps.add(new BasicNameValuePair("password", password)); try { httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpost); String rawJSON = EntityUtils.toString(response.getEntity()); response.getEntity().consumeContent(); Log.e("rawJSON", rawJSON); json = new JSONObject(rawJSON); if (json.getBoolean("success")) { return json.getString("secret"); } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.android.idtt.http.client.util.URIBuilder.java
private String encodeUserInfo(final String userInfo) { return URLEncodedUtils.encUserInfo(userInfo, Charset.forName(HTTP.UTF_8)); }
From source file:com.rumblefish.friendlymusic.api.WebRequest.java
public static HttpClient getNewHttpClient(int timelimit) { try {// w w w .jav a2s . c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(params, timelimit); HttpConnectionParams.setSoTimeout(params, timelimit); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { e.printStackTrace(); return new DefaultHttpClient(); } }
From source file:ch.uzh.ifi.attempto.ape.APEWebservice.java
/** * We create an HTTP GET query from the given parameters. If it turns out to be * too long (which we expect to happen very infrequently) then we fall back to creating * HTTP POST./*from w w w . j a v a 2 s . c o m*/ * <p/> * BUG: Old versions of the SWI-Prolog HTTP server do not handle POST queries correctly. * Hopefully this has been fixed in v5.11.9 (but I haven't tested it). * See the bug report in the SWI-Prolog mailing list in 2010-11-03. * * @param nvps List of name-value pairs * @return HTTP request (either GET or POST) */ private HttpUriRequest getHttpUriRequest(List<NameValuePair> nvps) { String getQuery = wsUrl + "?" + URLEncodedUtils.format(nvps, HTTP.UTF_8); if (getQuery.length() > MAX_HTTP_GET_LENGTH) { HttpPost httppost = new HttpPost(wsUrl); try { httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { // BUG: Assuming that this cannot happen } return httppost; } return new HttpGet(getQuery); }
From source file:org.openiot.gsn.http.rest.PushRemoteWrapper.java
public DataField[] registerAndGetStructure() throws IOException, ClassNotFoundException { // Create the POST request HttpPost httpPost = new HttpPost(initParams.getRemoteContactPointEncoded(lastReceivedTimestamp)); // Add the POST parameters httpPost.setEntity(new UrlEncodedFormEntity(postParameters, HTTP.UTF_8)); ////from ww w . j a v a 2s . c om httpPost.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); // Create local execution context HttpContext localContext = new BasicHttpContext(); // NotificationRegistry.getInstance().addNotification(uid, this); int tries = 0; AuthState authState = null; // while (tries < 2) { tries++; HttpResponse response = null; try { // Execute the POST request response = httpclient.execute(httpPost, localContext); // int sc = response.getStatusLine().getStatusCode(); // if (sc == HttpStatus.SC_OK) { logger.debug(new StringBuilder().append("Wants to consume the structure packet from ") .append(initParams.getRemoteContactPoint())); structure = (DataField[]) XSTREAM.fromXML(response.getEntity().getContent()); logger.debug("Connection established for: " + initParams.getRemoteContactPoint()); break; } else { if (sc == HttpStatus.SC_UNAUTHORIZED) authState = (AuthState) localContext.getAttribute(ClientContext.TARGET_AUTH_STATE); // Target host authentication required else if (sc == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) authState = (AuthState) localContext.getAttribute(ClientContext.PROXY_AUTH_STATE); // Proxy authentication required else { logger.error(new StringBuilder().append("Unexpected POST status code returned: ").append(sc) .append("\nreason: ").append(response.getStatusLine().getReasonPhrase())); } if (authState != null) { if (initParams.getUsername() == null || (tries > 1 && initParams.getUsername() != null)) { logger.error("A valid username/password required to connect to the remote host: " + initParams.getRemoteContactPoint()); } else { AuthScope authScope = authState.getAuthScope(); logger.warn(new StringBuilder().append("Setting Credentials for host: ") .append(authScope.getHost()).append(":").append(authScope.getPort())); Credentials creds = new UsernamePasswordCredentials(initParams.getUsername(), initParams.getPassword()); httpclient.getCredentialsProvider().setCredentials(authScope, creds); } } } } catch (RuntimeException ex) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection and release it back to the connection manager. logger.warn("Aborting the HTTP POST request."); httpPost.abort(); throw ex; } finally { if (response != null && response.getEntity() != null) { response.getEntity().consumeContent(); } } } if (structure == null) throw new RuntimeException("Cannot connect to the remote host."); return structure; }
From source file:org.addhen.smssync.net.MessageSyncHttpClient.java
/** * Get HTTP Entity populated with data in a format specified by the current sync scheme *///from w w w. j a v a2 s.c om private void setHttpEntity(SyncDataFormat format) throws Exception { switch (format) { case JSON: setStringEntity(DataFormatUtil.makeJSONString(getParams())); log("setHttpEntity format JSON"); Util.logActivities(context, "setHttpEntity format JSON"); break; case XML: //TODO: Make parent node URL specific as well setStringEntity(DataFormatUtil.makeXMLString(getParams(), "payload", HTTP.UTF_8)); log("setHttpEntity format XML"); Util.logActivities(context, context.getString(R.string.http_entity_format, "XML")); break; case YAML: setStringEntity(DataFormatUtil.makeYAMLString(getParams())); log("setHttpEntity format YAML"); Util.logActivities(context, context.getString(R.string.http_entity_format, "YAML")); break; case URLEncoded: log("setHttpEntity format URLEncoded"); Util.logActivities(context, context.getString(R.string.http_entity_format, "URLEncoded")); setEntity(new UrlEncodedFormEntity(getParams(), HTTP.UTF_8)); break; default: Util.logActivities(context, context.getString(R.string.invalid_data_format)); throw new Exception("Invalid data format"); } }