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.intel.iotkitlib.http.HttpGetTask.java
public CloudResponse doSync(String url) { HttpClient httpClient = new DefaultHttpClient(); try {//ww w . j av a 2 s .co m HttpContext localContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(url); //adding headers one by one for (NameValuePair nvp : headerList) { httpGet.addHeader(nvp.getName(), nvp.getValue()); } if (debug) { Log.e(TAG, "URI is : " + httpGet.getURI()); Header[] headers = httpGet.getAllHeaders(); for (int i = 0; i < headers.length; i++) { Log.e(TAG, "Header " + i + " is :" + headers[i].getName() + ":" + headers[i].getValue()); } } HttpResponse response = httpClient.execute(httpGet, localContext); if (response != null && response.getStatusLine() != null) { if (debug) Log.d(TAG, "response: " + response.getStatusLine().getStatusCode()); } HttpEntity responseEntity = response != null ? response.getEntity() : null; StringBuilder builder = new StringBuilder(); if (responseEntity != null) { BufferedReader reader = new BufferedReader( new InputStreamReader(responseEntity.getContent(), HTTP.UTF_8)); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } if (debug) Log.d(TAG, "Response received is :" + builder.toString()); } CloudResponse cloudResponse = new CloudResponse(); if (response != null) { cloudResponse.code = response.getStatusLine().getStatusCode(); } cloudResponse.response = builder.toString(); return cloudResponse; } catch (java.net.ConnectException cEx) { Log.e(TAG, cEx.getMessage()); return new CloudResponse(false, cEx.getMessage()); } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); return new CloudResponse(false, e.getMessage()); } }
From source file:com.catchnotes.api.VersionedCatchHttpClient.java
public void setAccessToken(String accessToken) { try {//from w w w.j a v a 2s .c o m mEncodedAccessToken = "access_token=" + URLEncoder.encode(accessToken, HTTP.UTF_8); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } }
From source file:org.yaoha.ApiConnector.java
public HttpResponse createNewChangeset() throws ClientProtocolException, IOException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException { URI uri = null;//from www .j a v a2 s . c o m try { uri = new URI("http", apiUrl, "/api/0.6/changeset/create", null, null); } catch (URISyntaxException e) { Log.e(ApiConnector.class.getSimpleName(), "Creating new changeset failed:"); Log.e(ApiConnector.class.getSimpleName(), e.getMessage()); } HttpPut request = new HttpPut(uri); request.setHeader(userAgentHeader); String requestString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<osm>" + "<changeset>" + "<tag k=\"created_by\" v=\"YAOHA\"/>" + "<tag k=\"comment\" v=\"Updating opening hours\"/>" + "</changeset>" + "</osm>"; HttpEntity entity = new StringEntity(requestString, HTTP.UTF_8); request.setEntity(entity); consumer.sign(request); return client.execute(request); }
From source file:com.shwy.bestjoy.utils.AndroidHttpClient.java
/** * Create a new HttpClient with reasonable defaults (which you can update). * * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. *//*from w w w . j a va 2 s . co m*/ public static HttpClient newInstance(String userAgent) { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sslSocketFactory = new SSLSocketFactoryEx(trustStore); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(params, false); // Default connection and socket timeout of 20 seconds. Tweak to taste. HttpConnectionParams.setConnectionTimeout(params, 60 * 1000); HttpConnectionParams.setSoTimeout(params, 60 * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); // Don't handle redirects -- return them to the caller. Our code // often wants to re-POST after a redirect, which we must do ourselves. HttpClientParams.setRedirecting(params, true); // Set the specified user agent and register standard protocols. HttpProtocolParams.setUserAgent(params, userAgent); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); // We use a factory method to modify superclass initialization // parameters without the funny call-a-static-method dance. return new AndroidHttpClient(manager, params); } catch (KeyStoreException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } return new DefaultHttpClient(); }
From source file:it.av.youeat.web.pubsubhubbub.Publisher.java
/** * @throws IOException If an input or output exception occurred * // w w w . j a v a 2 s. co m * @param The Hub address you want to publish it to * @param The topic_url you want to publish * * @return HTTP Response code. 200 is ok. Anything else smells like trouble */ public int execute(String hub, String topic_url) throws Exception { if ((hub != null) && (topic_url != null)) { // URL should validate if the strings are really URLs. Will throw // Exception if it isn't @SuppressWarnings("unused") URL verifying_topic_url = new URL(topic_url); @SuppressWarnings("unused") URL hub_url = new URL(hub); HttpPost httppost = new HttpPost(hub); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("hub.mode", "publish")); nvps.add(new BasicNameValuePair("hub.url", topic_url)); httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); httppost.setHeader("Content-type", "application/x-www-form-urlencoded"); httppost.setHeader("User-agent", "flagthis.pubsubhubbub 0.2"); GetThread thread = new GetThread(httpClient, httppost); thread.start(); thread.join(); return thread.getResponse().getStatusLine().getStatusCode(); } return 400; }
From source file:de.boksa.rt.rest.RTRESTClient.java
private RTRESTResponse getResponse(String url, List<NameValuePair> params) throws IOException { HttpPost postRequest = new HttpPost(this.getRestInterfaceBaseURL() + url); UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(params, HTTP.UTF_8); postEntity.setContentType("application/x-www-form-urlencoded"); postRequest.setEntity(postEntity);//from w w w . j a v a 2 s. co m HttpResponse httpResponse = this.httpClient.execute(postRequest); String responseBody = IOUtils.toString(httpResponse.getEntity().getContent(), HTTP.UTF_8); String[] responseSplit = responseBody.split("\n", 2); String header = responseSplit[0]; String body = ""; if (responseSplit.length == 2) { body = responseSplit[1]; } Matcher metaMatcher = PATTERN_RESPONSE_META.matcher(header); if (metaMatcher.matches()) { RTRESTResponse response = new RTRESTResponse(); response.setVersion(metaMatcher.group(1)); response.setStatusCode(Long.valueOf(metaMatcher.group(2))); response.setStatusMessage(metaMatcher.group(3)); response.setBody(body); return response; } else { System.err.println("not matched"); } return new RTRESTResponse(); }
From source file:at.diamonddogs.net.WebClientDefaultHttpClient.java
/** * Default {@link WebClient} constructor * /* w w w .j av a2 s . c om*/ * @param context * a {@link Context} object */ public WebClientDefaultHttpClient(Context context) { super(context); SSLSocketFactory sslSocketFactory = SSLHelper.getInstance().SSL_FACTORY_APACHE; if (sslSocketFactory != null) { sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sslSocketFactory, 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); httpClient = new DefaultHttpClient(ccm, params); } else { httpClient = new DefaultHttpClient(); } httpClient.setHttpRequestRetryHandler(this); if (followProtocolRedirect) { httpClient.setRedirectHandler(this); } }
From source file:com.google.code.maven.plugin.http.client.FormCredentials.java
/** * @param httpclient//from w w w . j av a 2 s . co m * @param beanResolver * @return * @throws IOException */ public void authenticate(DefaultHttpClient httpclient, Log log) throws IOException { HttpPost httpPost = new HttpPost(formUrl); UsernamePasswordCredentials credentials = toUsernamePasswordCredentials(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new Parameter(loginParameterName, credentials.getUserName()).toNameValuePair()); nvps.add(new Parameter(passwordParameterName, credentials.getPassword()).toNameValuePair()); for (Parameter parameter : parameters) { nvps.add(parameter.toNameValuePair()); } httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpPost); EntityUtils.consume(response.getEntity()); log.info("form authentication submitted to " + formUrl); }
From source file:com.phonty.improved.Balance.java
public String get() { StringBuilder builder = new StringBuilder(); String value = "0"; CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore);//from ww w .java 2s . c o m try { String locale = context.getResources().getConfiguration().locale.getCountry(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("locale", locale)); httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = client.execute(httppost); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); value = Parse(line); this.VALUE = value; } } else { this.VALUE = "0.0"; } } catch (ClientProtocolException e) { this.VALUE = "0.0"; e.printStackTrace(); } catch (IOException e) { this.VALUE = "0.0"; e.printStackTrace(); } return value; }
From source file:de.escidoc.core.test.sm.AggregationDefinitionTestBase.java
/** * Test retrieving the list of all aggregationDefinitions from the mock framework. * * @return The retrieved aggregationDefinitions as xml. * @throws Exception If anything fails./* w w w . j a v a 2 s. c o m*/ */ public String retrieveAggregationDefinitions() throws Exception { Object result = getAggregationDefinitionClient() .retrieveAggregationDefinitions(new HashMap<String, String[]>()); String xmlResult = null; if (result instanceof HttpResponse) { HttpResponse httpRes = (HttpResponse) result; assertHttpStatusOfMethod("", httpRes); xmlResult = EntityUtils.toString(httpRes.getEntity(), HTTP.UTF_8); } else if (result instanceof String) { xmlResult = (String) result; } return xmlResult; }