private void getFriend() { AsyncHttpClient myClient; myClient = new AsyncHttpClient(); myClient.setTimeout(SingleToneData.getInstance().getTimeOutValue()); PersistentCookieStore myCookieStore = new PersistentCookieStore(context); myClient.setCookieStore(myCookieStore); String url = context.getString(R.string.url_gift_list); RequestParams params = new RequestParams(); LoginUtils loginUtils = new LoginUtils(context); params.put("id", loginUtils.getId()); params.put("pw", loginUtils.getPw()); myClient.post( url, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { Log.i("(friend fragment)", new String(responseBody)); getGiftFinish(new String(responseBody)); } @Override public void onFailure( int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Toast.makeText( context, getResources().getString(R.string.on_failure), Toast.LENGTH_SHORT) .show(); } }); }
static { // // 使用默认的 cacheThreadPool client.setTimeout(150000); client.setConnectTimeout(150000); client.setMaxConnections(20); client.setResponseTimeout(200000); }
private searchMenuMgr() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore); socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); client = new AsyncHttpClient(); client.setSSLSocketFactory(socketFactory); client.setCookieStore(new PersistentCookieStore(Login_Main.getContext())); client.setTimeout(10000); } catch (KeyStoreException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } }
public void broadcastLocationFound(Location location) { String deviceId = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID); params = new RequestParams(); params.put("UID", deviceId); params.put("LAT", Double.toString(location.getLatitude())); params.put("LON", Double.toString(location.getLongitude())); params.put("ACU", Double.toString(location.getAccuracy())); params.put("SPD", Double.toString(location.getSpeed())); PersistentCookieStore CookieStore = new PersistentCookieStore(LocationService.this); CookieStore.clear(); AsyncHttpClient sendLocation = new AsyncHttpClient(false, 80, 443); sendLocation.setCookieStore(CookieStore); sendLocation.setTimeout(60000); sendLocation.post( url, params, new JsonHttpResponseHandler() { @Override public void onSuccess( int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); Log.i(TAG, response.toString()); } @Override public void onSuccess( int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONArray response) { super.onSuccess(statusCode, headers, response); Log.i(TAG, response.toString()); } @Override public void onSuccess( int statusCode, cz.msebera.android.httpclient.Header[] headers, String responseString) { super.onSuccess(statusCode, headers, responseString); Log.i(TAG, responseString); } @Override public void onFailure( int statusCode, cz.msebera.android.httpclient.Header[] headers, String responseString, Throwable throwable) { super.onFailure(statusCode, headers, responseString, throwable); Log.v(TAG, responseString, throwable); } }); }
// http://192.168.2.4:9000/imgupload/upload_image.php // http://192.168.2.4:9999/ImageUploadWebApp/uploadimg.jsp // Make Http call to upload Image to Php server public void makeHTTPCall() { AsyncHttpClient client = new AsyncHttpClient(); client.setTimeout(60000); // Don't forget to change the IP address to your LAN address. Port no as well. String URL = "http://hosamazzam.0fees.net/Blog_db_online/"; // URL="http://10.0.3.2/Blog_db/"; if (type == "user") { client.post( URL + "db_upload.php", params, new AsyncHttpResponseHandler() { // When the response returned by REST has Http // response code '200' @Override public void onSuccess(String response) { // Hide Progress Dialog up.finish_uploading(); System.out.println(response); } @Override public void onFailure(Throwable error, String content) { super.onFailure(error, content); System.out.println(content); up.failed(); } }); } else { client.post( URL + "db_upload_post.php", params, new AsyncHttpResponseHandler() { // When the response returned by REST has Http // response code '200' @Override public void onSuccess(String response) { // Hide Progress Dialog post.finish_uploading(); System.out.println(response); } @Override public void onFailure(Throwable error, String content) { super.onFailure(error, content); // System.out.println(content); post.failed(); } }); } }
public void send(ResponseListener listener, long roomId) { this.responseListener = listener; AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); asyncHttpClient.setTimeout(TIME_OUT); RequestParams requestParams = new RequestParams(); JniDanmu jniDanmu = new JniDanmu(context.getApplicationContext()); String time = String.valueOf(60L * (System.currentTimeMillis() / 1000L / 60L)); String roomStr = "room/" + roomId + "?"; String str1[] = new String[] {"aid", "client_sys", "time"}; String str2[] = new String[] { URLEncoder.encode("android"), URLEncoder.encode("android"), URLEncoder.encode(time) }; String str3[] = new String[] {}; String str4[] = new String[] {}; String result = jniDanmu.makeUrl(context.getApplicationContext(), roomStr, str1, str2, str3, str4, 1); asyncHttpClient.get( context, NetConfig.getRoomDetailInfoUrl(result), requestParams, responseHandler); }
public static void get( String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { clientProtocol.setTimeout(3); clientProtocol.get(baseUrl + url, params, responseHandler); }
private void getData() { url = bundle.getString(CommonConstants.BUSSINESSURI); RequestParams requestParams = new RequestParams(); requestParams.put(CommonConstants.TOKEN, "19d0ceaca45f9ee27e3c51df52786f1d904280f9"); requestParams.put(CommonConstants.OUTPUT, CommonConstants.JSON); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setMessage(getString(R.string.please_wait)); AsyncHttpClient client = new AsyncHttpClient(true, 80, 443); client.setTimeout(10000); client.get( url, requestParams, new JsonHttpResponseHandler() { @Override public void onStart() { progressDialog.show(); } @Override public void onFinish() { progressDialog.hide(); } @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { Log.e("JSON FLIGHT", response.toString() + ""); try { // getValue Gson gson = new Gson(); JSONArray photoArray = response .getJSONObject(CommonConstants.ALL_PHOTO) .getJSONArray(CommonConstants.PHOTO); for (int i = 0; i < photoArray.length(); i++) { fotos.add(gson.fromJson(photoArray.getJSONObject(i).toString(), Foto.class)); } JSONArray facilitiyArray = response .getJSONObject(CommonConstants.AVAIL_FACILITIES) .getJSONArray(CommonConstants.AVAIL_FACILITY); for (int i = 0; i < facilitiyArray.length(); i++) { facilitiys.add( gson.fromJson(facilitiyArray.getJSONObject(i).toString(), Facilitiy.class)); } JSONArray roomArray = response .getJSONObject(CommonConstants.RESULTS) .getJSONArray(CommonConstants.RESULT); for (int i = 0; i < roomArray.length(); i++) { rooms.add(gson.fromJson(roomArray.getJSONObject(i).toString(), Room.class)); } JSONObject breadcrumbObject = response.getJSONObject(CommonConstants.BREADCRUMB); breadcrumb = gson.fromJson(breadcrumbObject.toString(), Breadcrumb.class); JSONObject generalObject = response.getJSONObject(CommonConstants.GENERAL); general = gson.fromJson(generalObject.toString(), General.class); String primaryPhotos = response.getString(CommonConstants.PRIMARYPHOTO); // setValue ((TextView) findViewById(R.id.title_hotel)).setText(breadcrumb.businessName); ((TextView) findViewById(R.id.location_hotel)).setText(breadcrumb.areaName); Picasso.with(ProfileHotelActivity.this) .load(primaryPhotos) .error(R.drawable.bg_sample) .into(((ImageView) findViewById(R.id.iv_primaryphoto))); viewPager.setAdapter(new TabAdapter(getSupportFragmentManager())); tabLayout.setupWithViewPager(viewPager); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { Toast.makeText(ProfileHotelActivity.this, R.string.RTO, Toast.LENGTH_SHORT).show(); } @Override public void onFailure( int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { Log.e("JSON ProfileHotel", errorResponse + ""); ErrorException.getError(ProfileHotelActivity.this, errorResponse); } }); }
static { // HttpClient配置 client.setTimeout(10 * 1000); }