Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HttpClient httpclient = getNewHttpClient();
- HttpPost request = new HttpPost(uri);
- try {
- request.addHeader("Authorization", "autorisation string");
- request.addHeader("Content-Type", "application/json; charset=utf-8");
- request.setEntity(new ByteArrayEntity(Query.getBytes("utf-8")));
- HttpHost hh = new HttpHost(uri.getHost());
- Log.w("myApp", "Port: " + Integer.toString(hh.getPort()));
- HttpResponse response = httpclient.execute(new HttpHost(uri.getHost()),request);
- InputStream inputStream = response.getEntity().getContent();
- final char[] buffer = new char[0x10000];
- responseString = new StringBuilder();
- Reader in = new InputStreamReader(inputStream, "utf-8");
- int read;
- do {
- read = in.read(buffer, 0, buffer.length);
- if (read > 0) {
- responseString.append(buffer, 0, read);
- }
- } while (read >= 0);
- } catch (Exception e) {
- e.printStackTrace();
- }
- public HttpClient getNewHttpClient() {
- HttpClient hc = null;
- try {
- 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("https", sf, 443));
- registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
- ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
- hc = new DefaultHttpClient(ccm, params);
- } catch (Exception e) {
- Log.w("myApp",e.toString());
- hc = new DefaultHttpClient();
- }
- return hc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement