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.appfirst.communication.AFHttpClient.java
public DefaultHttpClient getAFHttpClient() { try {/*from w w w . ja va 2s. c o m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); try { trustStore.load(null, null); } catch (CertificateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } SSLSocketFactory sf = new AFSSLSocketFactory(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", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (NoSuchAlgorithmException nsae) { Log.e(TAG, nsae.getMessage()); return new DefaultHttpClient(); } catch (KeyManagementException kme) { Log.e(TAG, kme.getMessage()); return new DefaultHttpClient(); } catch (KeyStoreException kse) { Log.e(TAG, kse.getMessage()); return new DefaultHttpClient(); } catch (UnrecoverableKeyException uke) { Log.e(TAG, uke.getMessage()); return new DefaultHttpClient(); } }
From source file:org.anhonesteffort.flock.registration.OwsRegistration.java
protected static String getHrefWithParameters(String href, List<NameValuePair> params) { String result = href + "?"; try {/*w w w.j av a 2 s .com*/ for (NameValuePair param : params) result += param.getName() + "=" + URLEncoder.encode(param.getValue(), HTTP.UTF_8) + "&"; } catch (UnsupportedEncodingException e) { Log.e("OwsRegistrtaion", e.toString()); } return result; }
From source file:com.microsoft.live.mock.MockHttpEntity.java
@Override public Header getContentEncoding() { return new BasicHeader("Content-encoding", HTTP.UTF_8); }
From source file:org.apache.tuscany.sca.host.http.client.HttpClientFactory.java
public HttpClient createHttpClient() { HttpParams defaultParameters = new BasicHttpParams(); //defaultParameters.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 10); ConnManagerParams.setMaxTotalConnections(defaultParameters, 1024); ConnPerRoute connPerRoute = new ConnPerRouteBean(256); ConnManagerParams.setMaxConnectionsPerRoute(defaultParameters, connPerRoute); HttpProtocolParams.setContentCharset(defaultParameters, HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(defaultParameters, 60000); HttpConnectionParams.setSoTimeout(defaultParameters, 60000); SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes// www.jav a 2s .co m .register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(), 80)); supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(defaultParameters, supportedSchemes); return new DefaultHttpClient(connectionManager, defaultParameters); }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPICore.java
@Override public boolean Login(ZenossCredentials credentials) throws Exception { if (credentials.URL.contains("https://")) { this.PrepareSSLHTTPClient(); } else {/*from w ww . java 2 s . c o m*/ this.PrepareHTTPClient(); //httpclient = new DefaultHttpClient(); } if (!credentials.BAUser.equals("") || !credentials.BAPassword.equals("")) { //Log.i("Auth","We have some auth credentials"); CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(credentials.BAUser, credentials.BAPassword)); httpclient.setCredentialsProvider(credProvider); } HttpPost httpost = new HttpPost(credentials.URL + "/zport/acl_users/cookieAuthHelper/login"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__ac_name", credentials.UserName)); nvps.add(new BasicNameValuePair("__ac_password", credentials.Password)); nvps.add(new BasicNameValuePair("submitted", "true")); nvps.add(new BasicNameValuePair("came_from", credentials.URL + "/zport/dmd")); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); // Response from POST not needed, just the cookie HttpResponse response = httpclient.execute(httpost); // Consume so we can reuse httpclient response.getEntity().consumeContent(); //Set the variables for later this.ZENOSS_INSTANCE = credentials.URL; this.ZENOSS_USERNAME = credentials.UserName; this.ZENOSS_PASSWORD = credentials.Password; Log.e("CheckLoggedIn", Integer.toString(response.getStatusLine().getStatusCode())); reqCount++; return this.CheckLoggedIn(); }
From source file:org.bishoph.oxdemo.util.CreateTaskAction.java
@Override protected JSONObject doInBackground(Object... params) { try {//from w w w .ja v a2 s. com String uri = (String) params[0]; String title = (String) params[1]; if (title == null && folder_id > 0) { Log.v("OXDemo", "Either title or folder_id missing. Done nothing!"); return null; } Log.v("OXDemo", "Attempting to create task " + title + " on " + uri); JSONObject jsonobject = new JSONObject(); jsonobject.put("folder_id", folder_id); jsonobject.put("title", title); jsonobject.put("status", 1); jsonobject.put("priority", 0); jsonobject.put("percent_completed", 0); jsonobject.put("recurrence_type", 0); jsonobject.put("private_flag", false); jsonobject.put("notification", false); Log.v("OXDemo", "Body = " + jsonobject.toString()); HttpPut httpput = new HttpPut(uri); StringEntity stringentity = new StringEntity(jsonobject.toString(), HTTP.UTF_8); stringentity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8")); httpput.setHeader("Accept", "application/json, text/javascript"); httpput.setHeader("Content-type", "application/json"); httpput.setEntity(stringentity); HttpResponse response = httpclient.execute(httpput, localcontext); Log.v("OXDemo", "Created task " + title); HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity); Log.d("OXDemo", "<<<<<<<\n" + result + "\n\n"); JSONObject jsonObj = new JSONObject(result); jsonObj.put("title", title); return jsonObj; } catch (JSONException e) { Log.e("OXDemo", e.getMessage()); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:de.chaosdorf.meteroid.longrunningio.LongRunningIOGet.java
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(url); try {//from w ww . j av a 2 s. c om HttpResponse response = httpClient.execute(httpGet, localContext); int code = response.getStatusLine().getStatusCode(); if (code >= 400 && code <= 599) { callback.displayErrorMessage(id, response.getStatusLine().getReasonPhrase()); return null; } HttpEntity entity = response.getEntity(); return EntityUtils.toString(entity, HTTP.UTF_8); } catch (Exception e) { callback.displayErrorMessage(id, e.getLocalizedMessage()); return null; } }
From source file:edu.emory.library.utils.EULHttpUtils.java
/** * Utility method to POST to a URL and read the result into a string * @param url url to be read/* w ww .ja v a 2s.c o m*/ * @param headers HashMap of request headers * @param parameters HashMap of parameters */ public static String postUrlContents(String url, HashMap<String, String> headers, HashMap<String, String> parameters) throws Exception { String response = null; HttpClient client = new DefaultHttpClient(); HttpPost postMethod = new HttpPost(url); // add any request headers specified for (Map.Entry<String, String> header : headers.entrySet()) { postMethod.addHeader(header.getKey(), header.getValue()); } List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> param : parameters.entrySet()) { nvps.add(new BasicNameValuePair(param.getKey(), param.getValue())); } postMethod.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); // returns the response content as string on success response = client.execute(postMethod, responseHandler); // could throw HttpException or IOException // TODO: catch/handle errors (esp. periodic 503 when Spotlight is unavailable) postMethod.releaseConnection(); return response; }
From source file:com.allwinner.theatreplayer.launcher.service.UpdateService.java
private void sendPost(String server_url) { // Log.v(TAG, "send post to server"); HttpPost post = new HttpPost(server_url); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("guid", "646212C46B774f95BBBE2F9CCFF32797")); params.add(new BasicNameValuePair("service_type", "APK_UPDATE")); params.add(new BasicNameValuePair("para_serial", Utils.rcId)); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(httpParameters, Utils.CHECK_TIMEOUT); HttpClient httpClient = new DefaultHttpClient(httpParameters); try {//from www.ja v a2 s . co m post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpResponse response = httpClient.execute(post); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String data = EntityUtils.toString(entity, "UTF-8"); Utils.saveUpdateJson(data, Utils.sdcardPathQQ + "/update.json"); JSONObject jsonobj = new JSONObject(data); int version = jsonobj.getInt("version"); // Log.i(TAG, "?md5 = "+jsonobj.getString("md5")); // Log.i(TAG, "version = "+version); // Log.i(TAG, "local = "+Utils.getVersionCode(this)); // Log.i(TAG, "url = "+jsonobj.getString("url")); if (version > Utils.getVersionCode(this)) { // Intent intent = new Intent(); intent.setAction(APKONCHECKED); sendBroadcast(intent); } } else { Log.i(TAG, "1: response status: " + response.getStatusLine().getStatusCode()); } } catch (Exception e) { Log.i(TAG, "Exception ERROR_UNKNOWN" + e.getMessage()); } }
From source file:hu.sztaki.lpds.dcibridge.util.io.HttpHandler.java
public InputStream getStream(Hashtable<String, String> pValue) throws IOException { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); Enumeration<String> enm = pValue.keys(); String key;//from w w w. j a v a 2s . com while (enm.hasMoreElements()) { key = enm.nextElement(); nvps.add(new BasicNameValuePair(key, pValue.get(key))); } httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); return entity.getContent(); }