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:net.reichholf.dreamdroid.helpers.SimpleHttpClient.java
/** * @param uri/* w ww . j a va2s .co m*/ * @param parameters * @return */ public String buildUrl(String uri, List<NameValuePair> parameters) { String parms = URLEncodedUtils.format(parameters, HTTP.UTF_8).replace("+", "%20"); if (!uri.contains("?")) uri += "?"; return mPrefix + mProfile.getHost() + ":" + mProfile.getPortString() + uri + parms; }
From source file:com.dalaran.async.task.http.AbstractHTTPService.java
public static HttpClient getNewHttpClient() { try {/*from www .ja v a2s . com*/ 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); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.socialize.net.DefaultHttpClientFactory.java
@Override public void init(SocializeConfig config) throws SocializeException { try {//from w w w.ja v a2 s . c om if (logger != null && logger.isDebugEnabled()) { logger.debug("Initializing " + getClass().getSimpleName()); } params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(params, config.getIntProperty(SocializeConfig.HTTP_CONNECTION_TIMEOUT, 10000)); HttpConnectionParams.setSoTimeout(params, config.getIntProperty(SocializeConfig.HTTP_SOCKET_TIMEOUT, 10000)); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); connectionManager = new ThreadSafeClientConnManager(params, registry); monitor = new IdleConnectionMonitorThread(connectionManager); monitor.setDaemon(true); monitor.start(); if (logger != null && logger.isDebugEnabled()) { logger.debug("Initialized " + getClass().getSimpleName()); } destroyed = false; } catch (Exception e) { throw new SocializeException(e); } }
From source file:org.andstatus.app.net.http.HttpConnectionApacheCommon.java
private void fillMultiPartPost(HttpPost postMethod, JSONObject formParams) throws ConnectionException { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); Uri mediaUri = null;//from www.ja va 2 s .c o m String mediaPartName = ""; Iterator<String> iterator = formParams.keys(); ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8); while (iterator.hasNext()) { String name = iterator.next(); String value = formParams.optString(name); if (HttpConnection.KEY_MEDIA_PART_NAME.equals(name)) { mediaPartName = value; } else if (HttpConnection.KEY_MEDIA_PART_URI.equals(name)) { mediaUri = UriUtils.fromString(value); } else { // see http://stackoverflow.com/questions/19292169/multipartentitybuilder-and-charset builder.addTextBody(name, value, contentType); } } if (!TextUtils.isEmpty(mediaPartName) && !UriUtils.isEmpty(mediaUri)) { try { InputStream ins = MyContextHolder.get().context().getContentResolver().openInputStream(mediaUri); ContentType contentType2 = ContentType.create(MyContentType.uri2MimeType(mediaUri, null)); builder.addBinaryBody(mediaPartName, ins, contentType2, mediaUri.getPath()); } catch (SecurityException e) { throw new ConnectionException("mediaUri='" + mediaUri + "'", e); } catch (FileNotFoundException e) { throw new ConnectionException("mediaUri='" + mediaUri + "'", e); } } postMethod.setEntity(builder.build()); }
From source file:com.wms.ezyoukuuploader.sdk.task.FetchYoukuAccessTokenTask.java
@SuppressWarnings("deprecation") @Override// www . j a va 2 s .c o m protected String doInBackground(String... params) { // params[0] is refresh token String refreshToken = params[0]; String accessToken = null; HttpPost httpPost = new HttpPost(YoukuConstants.YOUKU_OAUTH2_URL); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair(YoukuConstants.PARAM_CLIENT_ID, context.getString(R.string.YOUKU_APP_CLIENT_ID))); parameters.add(new BasicNameValuePair(YoukuConstants.PARAM_CLIENT_SECRET, context.getString(R.string.YOUKU_APP_CLIENT_SECRET))); parameters.add( new BasicNameValuePair(YoukuConstants.PARAM_GRANT_TYPE, YoukuConstants.GRANT_TYPE_REFRESH_TOKEN)); parameters.add(new BasicNameValuePair(YoukuConstants.PARAM_REFRESH_TOKEN, refreshToken)); try { httpPost.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost); if (httpResponse.getStatusLine().getStatusCode() == 200) { String result = EntityUtils.toString(httpResponse.getEntity()); JSONObject object = new JSONObject(result); accessToken = object.getString(YoukuConstants.PARAM_ACCESS_TOKEN); String newRefreshToken = object.getString(YoukuConstants.PARAM_REFRESH_TOKEN); SharedPreferenceUtil.savePreferenceItemByName(context, SharedPreferenceUtil.YoukuRefreshToken, newRefreshToken); SharedPreferenceUtil.savePreferenceItemByName(context, SharedPreferenceUtil.YoukuAccessToken, accessToken); } } catch (Exception e) { // accessToken will remain null } ; return accessToken; }
From source file:org.safegees.safegees.util.HttpUrlConnection.java
public String performGetCall(String requestURL, HashMap<String, String> postDataParams, String userCredentials) { DefaultHttpClient httpclient = new DefaultHttpClient(); final HttpParams httpConnParams = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpConnParams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpConnParams, READ_TIMEOUT); HttpGet httpGet = new HttpGet(requestURL); //Add the auth header if (userCredentials != null) httpGet.addHeader("auth", userCredentials); HttpResponse response = null;//from w ww .j a va 2 s . c om String responseStr = null; try { response = httpclient.execute(httpGet); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == 200 || (statusLine.getStatusCode() > 200 && statusLine.getStatusCode() < 300)) { responseStr = EntityUtils.toString(response.getEntity(), HTTP.UTF_8); } else { Log.e("GET ERROR", response.getStatusLine().toString()); } } catch (IOException e) { e.printStackTrace(); } return responseStr; }
From source file:com.harlap.test.http.MockHttpServerBehaviour.java
@Test public void testShouldHandlePostRequests() throws ClientProtocolException, IOException { // Given a mock server configured to respond to a POST / with data // "Hello World" with an ID server.expect(MockHttpServer.Method.POST, "/", "Hello World").respondWith(200, "text/plain", "ABCD1234"); // When a request for POST / arrives HttpPost req = new HttpPost(baseUrl + "/"); req.setEntity(new StringEntity("Hello World", HTTP.UTF_8)); ResponseHandler<String> handler = new BasicResponseHandler(); String responseBody = client.execute(req, handler); // Then the response is "ABCD1234" assertEquals("ABCD1234", responseBody); }
From source file:com.seer.datacruncher.load.LoadRunner.java
/** * Function To Start Load Testing/* w w w . ja va2 s . c o m*/ */ public void startLoadTesting() { properties = new Properties(); InputStream in = LoadRunner.class.getClassLoader().getResourceAsStream("load.properties"); try { properties.load(in); } catch (Exception e) { System.out.println("load.properties not found in classpath"); e.printStackTrace(); return; } String url = properties.getProperty("url"); DefaultHttpClient client = null; try { for (int i = 1; i <= Integer.valueOf(properties.getProperty("iterations")); i++) { for (int j = 1; j <= Integer.valueOf(properties.getProperty("no_of_parallel_users")); j++) { System.out.println("--- Iteration: " + i + " | Request: " + j + " ---"); client = createClient(); /** LOGIN **/ HttpPost httpPostLogin = new HttpPost(url + "/login.json"); System.out.println("Requesting: " + httpPostLogin.getURI()); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("userName", properties.getProperty("user_name"))); nvps.add(new BasicNameValuePair("password", properties.getProperty("password"))); httpPostLogin.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = client.execute(httpPostLogin); printResponse(response); /** APPLICATION **/ // Read if ((properties.getProperty("application") + "").indexOf("read") != -1) { postRequest(client, "applicationsRead.json"); } /** DATABASES **/ // Read if ((properties.getProperty("database") + "").indexOf("read") != -1) { postRequest(client, "databasesRead.json"); } /** SCHEMAS **/ // Read if ((properties.getProperty("schema") + "").indexOf("read") != -1) { postRequest(client, "schemasRead.json"); } /** TASKS (SCHEDULERS) **/ // Read if ((properties.getProperty("task") + "").indexOf("read") != -1) { postRequest(client, "tasksRead.json"); } /** USERS **/ // Read if ((properties.getProperty("user") + "").indexOf("read") != -1) { postRequest(client, "usersRead.json"); } /** REPORTS **/ // Read if ((properties.getProperty("report") + "").indexOf("read") != -1) { postRequest(client, "realTimeGraph.json"); } } Thread.sleep(Integer.valueOf(properties.getProperty("delay_in_secs")) * 1000); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { if (null != client) client.getConnectionManager().shutdown(); } }
From source file:de.escidoc.core.test.sm.ScopeTestBase.java
/** * Test updating an Scope of the mock framework. * * @param id The id of the Scope.//from ww w. jav a 2 s . co m * @param xml The xml representation of the Scope. * @return The updated Scope. * @throws Exception If anything fails. */ public String update(final String id, final String xml) throws Exception { Object result = getScopeClient().update(id, xml); String xmlResult = null; if (result instanceof HttpResponse) { HttpResponse httpRes = (HttpResponse) result; xmlResult = EntityUtils.toString(httpRes.getEntity(), HTTP.UTF_8); if (httpRes.getStatusLine().getStatusCode() >= 300 || httpRes.getStatusLine().getStatusCode() < 200) { throw new Exception(xmlResult); } } else if (result instanceof String) { xmlResult = (String) result; } return xmlResult; }