@Override public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) { if (client instanceof SyncHttpClient) { new Thread(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "Before Request"); client.get(SynchronousClientSample.this, URL, headers, null, responseHandler); Log.d(LOG_TAG, "After Request"); } }).start(); } else { Log.e(LOG_TAG, "Error, not using SyncHttpClient"); } /** * SyncHttpClient does not return RequestHandle, * it executes each request directly, * therefore those requests are not in cancelable threads * */ return null; }
@NonNull private SyncHttpClient getUnsafeSyncHttpClient() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException, UnrecoverableKeyException { // We initialize a default Keystore KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); // We load the KeyStore trustStore.load(null, null); // We initialize a new SSLSocketFactory MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore); // We set that all host names are allowed in the socket factory socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // We initialize the Async Client SyncHttpClient client = new SyncHttpClient(); // We set the timeout to 30 seconds client.setTimeout(TIMEOUT); // We set the SSL Factory client.setSSLSocketFactory(socketFactory); client.setEnableRedirects(true); client.setUserAgent("Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36"); return client; }
/** * Upload files with {@link com.loopj.android.http.SyncHttpClient} * * @param url * @param paramsList * @param fileParams * @param files * @param responseHandler */ public static void uploadFiles(String url, List<NameValuePair> paramsList, String fileParams, List<File> files, AsyncHttpResponseHandler responseHandler) throws Exception { SyncHttpClient syncHttpClient = new SyncHttpClient(); RequestParams params = new RequestParams(); if (BasicUtils.judgeNotNull(paramsList)) { for (NameValuePair nameValuePair : paramsList) { params.put(nameValuePair.getName(), nameValuePair.getValue()); } } if (BasicUtils.judgeNotNull(files)) params.put(fileParams, files); syncHttpClient.setTimeout(timeout); syncHttpClient.post(url, params, responseHandler); }
/** * Creates new instance of {@link BaseGsonLoader} that is going to execute HTTP GET method with no url parameters. * Use set methods provided by this class to customize http request. * * @param context used by loader. * @param url for HTTP request. */ public BaseGsonLoader(Context context, String url) { super(context); this.syncHttpClient = new SyncHttpClient() { @Override public String onRequestFailed(Throwable error, String content) { errorThrowable = error; errorResponse = content; return null; } }; this.url = url; this.requestParams = null; this.httpMethod = HttpMethod.GET; this.headers = null; this.entity = null; this.contentType = null; }
public static RequestHandle refreshTokens(Context context, String scopes, AsyncHttpResponseHandler handler) { SyncHttpClient client = new SyncHttpClient(); RequestParams params = new RequestParams(); params.put("client_id", context.getString(R.string.facebook_app_id)); params.put("redirect_uri", "https://www.facebook.com/connect/login_success.html"); params.put("response_type", "token"); params.put("scopes", scopes); return client.get("https://www.facebook.com/v2.9/dialog/oauth", params, handler); }
private void init() { asyncHttpClient = new SyncHttpClient(); asyncHttpClient.setTimeout(60 * 1000); asyncHttpClient.setSSLSocketFactory(MySSLSocketFactory.getFixedSocketFactory()); asyncHttpClient.setCookieStore(new BasicCookieStore());//new PersistentCookieStore(context); addHeader("Accept", "application/json;"); addHeader("Connection", "keep-alive"); }
private NetWorkManager() { xuankeHttpClient = new SyncHttpClient(); benyanHttpClient = new SyncHttpClient(); cardRestHttpClient = new SyncHttpClient(); cookies4m3 = new HashMap<>(); // semaphore = new Semaphore(networkThreadCnt, true); }
/** * Upload file with {@link com.loopj.android.http.SyncHttpClient} * * @param url * @param paramsList * @param fileParams * @param file * @param responseHandler * @throws FileNotFoundException */ public static void uploadFile(String url, List<NameValuePair> paramsList, String fileParams, File file, AsyncHttpResponseHandler responseHandler) throws FileNotFoundException { SyncHttpClient syncHttpClient = new SyncHttpClient(); RequestParams params = new RequestParams(); if (BasicUtils.judgeNotNull(paramsList)) { for (NameValuePair nameValuePair : paramsList) { params.put(nameValuePair.getName(), nameValuePair.getValue()); } } if (BasicUtils.judgeNotNull(file)) params.put(fileParams, file); syncHttpClient.setTimeout(timeout); syncHttpClient.post(url, params, responseHandler); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setAsyncHttpClient(new SyncHttpClient()); }
public static RequestHandle events(String accessToken, RequestParams params, AsyncHttpResponseHandler handler) { SyncHttpClient client = new SyncHttpClient(); params.add(ACCESS_TOKEN_PARAM, accessToken); return client.get(BASE_URL + "/me/events", params, handler); }
public static RequestHandle fetchBirthdayICal(String birthdayICalUri, AsyncHttpResponseHandler handler) { SyncHttpClient client = new SyncHttpClient(); // Pretend we are cURL, so that Facebook does not redirect us to facebook.com/unsupportedbrowser client.setUserAgent("curl/7.55.1"); return client.get(birthdayICalUri, handler); }
public Builder(Context context) { syncClient = new SyncHttpClient(); this.context = context.getApplicationContext(); }
public SyncHttpClient getCardRestHttpClient() { return cardRestHttpClient; }
public SyncHttpClient getXuanKeHttpClient() { return xuankeHttpClient; }
public SyncHttpClient getBenyanHttpClient() { return benyanHttpClient; }
public void resetBenYanHttpClient() { benyanHttpClient = new SyncHttpClient(); }
public void resetXuankeHttpClient() { xuankeHttpClient = new SyncHttpClient(); }
public void resetCardRestHttpClient() { cardRestHttpClient = new SyncHttpClient(); }
private SyncHttpClient createClient() { return new SyncHttpClient(); }
/** * @return 同步网络请求客户端 */ public AsyncHttpClient getSyncHttpClient() { return new SyncHttpClient(); }
public SyncHttpClient getSyncHttpClient() { return this.client; }
private SyncHttpClient getSyncHttpClient() { return new SyncHttpClient(); }
/** * Get syncronus client. Syncronus client is since everything happens in loader thread. * * @return {@link SyncHttpClient} used by loader. */ public SyncHttpClient getSyncClient() { return syncHttpClient; }