Java Code Examples for com.loopj.android.http.AsyncHttpClient#post()

The following examples show how to use com.loopj.android.http.AsyncHttpClient#post() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WelcomeActivity.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 更新APP
 */
private void updateApp() {
    startTime = System.currentTimeMillis(); // 获取系统当前的时间
    // 判断手机是否可以联网
    if (!NetStateUtil.isConnected(this)) {
        ToastUtil.show(WelcomeActivity.this, "网络异常!");
        toLoginPager();
    } else {
        String updateUrl = ApiRequestUrl.UPDATE; // 获取联网请求更新应用的路径
        // 使用AsyncHttpClient实现联网获取版本信息
        AsyncHttpClient client = new AsyncHttpClient();
        client.post(updateUrl, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String json) {
                LogUtils.json(TAG, json);
                // 使用fastJson解析json数据
                updateInfo = JSON.parseObject(json, UpdateInfo.class);
                handler.sendEmptyMessage(WHAT_DOWNLOAD_VERSION_SUCCESS);
            }

            @Override
            public void onFailure(Throwable error, String content) {
                LogUtils.e(TAG, "Throwable:" + error.getMessage() + ",content:" + content);
                ToastUtil.show(WelcomeActivity.this, "联网获取更新数据失败!");
                toLoginPager();
            }
        });
    }
}
 
Example 2
Source File: SubscriptionManager.java    From pusher-websocket-android with MIT License 6 votes vote down vote up
public void sendSubscription(Subscription subscription) {
    String interest =  subscription.getInterest();
    InterestSubscriptionChange change = subscription.getChange();

    JSONObject json = new JSONObject();
    try {
        json.put("app_key", appKey);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
    StringEntity entity = new StringEntity(json.toString(), "UTF-8");

    String url = options.buildNotificationURL("/clients/" + clientId + "/interests/" + interest);
    ResponseHandlerInterface handler = factory.newSubscriptionChangeHandler(subscription);
    AsyncHttpClient client = factory.newHttpClient();
    switch (change) {
        case SUBSCRIBE:
            client.post(context, url, entity, "application/json", handler);
            break;
        case UNSUBSCRIBE:
            client.delete(context, url, entity, "application/json", handler);
            break;
    }
}
 
Example 3
Source File: AsyncHttpUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 上传文件
 *
 * @return
 */
public static void upLoadFile(String url, File file, AsyncHttpResponseHandler handler) throws FileNotFoundException {
    RequestParams params = new RequestParams();
    params.put("username", "张鸿洋");
    params.put("password", "123");
    params.put("mFile", file);
    AsyncHttpClient client = getHttpClient();
    client.addHeader("Content-disposition", "mFile=\"" + file.getName() + "\"");
    client.addHeader("APP-Key", "APP-Secret222");
    client.addHeader("APP-Secret", "APP-Secret111");
    client.post(url, params, handler);
}
 
Example 4
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP POST request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param responseHandler
 */
public static void postWithCookie(Context context, String url, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    //  myCookieStore.clear();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example 5
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Perform a HTTP POST request with cookies which are defined in hashmap
 *
 * @param context
 * @param url
 * @param hashMap
 * @param responseHandler
 */
public static void postUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), responseHandler);
}
 
Example 6
Source File: TokenRegistry.java    From pusher-websocket-android with MIT License 4 votes vote down vote up
private void upload(StringEntity params) {
    String url = options.buildNotificationURL("/clients");
    AsyncHttpClient client = factory.newHttpClient();
    JsonHttpResponseHandler handler = factory.newTokenUploadHandler(context, listenerStack);
    client.post(context, url, params, "application/json", handler);
}
 
Example 7
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a HTTP POST request with cookie which generate by own context
 *
 * @param context
 * @param url
 * @param params
 * @param responseHandler
 */
public static void postWithCookie(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
    AsyncHttpClient client = new AsyncHttpClient();
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    client.setCookieStore(myCookieStore);
    client.post(getAbsoluteUrl(url), params, responseHandler);
}