Example usage for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder

List of usage examples for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder

Introduction

In this page you can find the example usage for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder.

Prototype

FormEncodingBuilder

Source Link

Usage

From source file:com.example.diego.proyecto1edd.TestWebServer.java

public boolean Login(String dato, String pass, String empresa, String depto) {
    RequestBody Cuerpo = new FormEncodingBuilder().add("dato", dato).add("dato1", pass).add("dato2", empresa)
            .add("dato3", depto)

            .build();/* w  ww .ja  va 2  s.c o m*/
    String r = getString("metodoWeb", Cuerpo);
    if (r == "HECHO") {
        return true;

    } else {
        return false;
    }

}

From source file:com.fysl.app.main.LoginActivity.java

License:Open Source License

private void loginInserver(String tel, String password) {

    final ProgressDialog progressDialog = new ProgressDialog(this);

    progressDialog.setMessage("...");
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.show();/*w  ww . j  a  v a 2  s.  c  o  m*/

    // ???

    RequestBody formBody = new FormEncodingBuilder()

            .add("tel", tel).add("password", MD5Util.getMD5String(password)).build();

    Request request = new Request.Builder().url(Constant.URL_LOGIN).post(formBody).build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Request arg0, IOException arg1) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    progressDialog.dismiss();
                    Toast.makeText(getApplicationContext(), "?...", Toast.LENGTH_SHORT)
                            .show();
                }

            });
        }

        @Override
        public void onResponse(Response arg0) throws IOException {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    progressDialog.dismiss();

                }

            });
            // System.out.println("response--->" + arg0.body().string());

            if (arg0.isSuccessful()) {
                String result = arg0.body().string();

                System.out.println("result--->" + result);
                final JSONObject json = JSONObject.parseObject(Constant.jsonTokener(result));

                if (json.getInteger("code") == 1000) {

                    final JSONObject userJson = json.getJSONObject("user");
                    DemoApplication.getInstance().savaUserInfo(userJson);
                    // ?
                    // SDK?

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {

                            // TODO Auto-generated method stub
                            loginHuanxin(userJson);
                        }

                    });
                }

            }
        }

    });

}

From source file:com.fysl.app.main.LoginActivity.java

License:Open Source License

private void getFriendsInfoInServer(String allFriends) {

    final ProgressDialog progressDialog = new ProgressDialog(this);

    progressDialog.setMessage("?...");
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.show();/* w w  w . j av a 2  s. c  o  m*/

    // ???

    RequestBody formBody = new FormEncodingBuilder()

            .add("allFriends", allFriends).build();

    Request request = new Request.Builder().url(Constant.URL_GET_FRIENDS).post(formBody).build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Request arg0, IOException arg1) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    progressDialog.dismiss();
                    Toast.makeText(getApplicationContext(), "?...", Toast.LENGTH_SHORT)
                            .show();
                }

            });
        }

        @Override
        public void onResponse(Response arg0) throws IOException {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub

                    progressDialog.dismiss();

                }

            });
            // System.out.println("response--->" + arg0.body().string());

            if (arg0.isSuccessful()) {
                String result = arg0.body().string();

                System.out.println("result--->" + result);
                final JSONObject json = JSONObject.parseObject(Constant.jsonTokener(result));

                if (json.getInteger("code") == 1000) {

                    final JSONArray friends = json.getJSONArray("friends");
                    Map<String, EaseUser> usermap = new HashMap<String, EaseUser>();
                    for (int i = 0; i < friends.size(); i++) {
                        JSONObject friend = friends.getJSONObject(i);
                        EaseUser user = JSON2User.getUser(friend);
                        usermap.put(user.getUsername(), user);

                    }

                    DemoHelper.getInstance().getContactList().putAll(usermap);
                    UserDao dao = new UserDao(LoginActivity.this);
                    dao.saveContactList(new ArrayList(usermap.values()));

                    // // ?
                    // // SDK?
                    //
                    // runOnUiThread(new Runnable() {
                    //
                    // @Override
                    // public void run() {
                    // // TODO Auto-generated method stub
                    // loginHuanxin(friends);
                    // }
                    //
                    // });
                }

            }
        }

    });

}

From source file:com.fysl.app.ui.AddContactActivity.java

License:Open Source License

private void searchUserInServer(String value) {

    final ProgressDialog pd = new ProgressDialog(AddContactActivity.this);
    pd.setCanceledOnTouchOutside(false);
    pd.setMessage("?...");
    pd.show();//from  w  w  w  . j av  a 2 s  . c o m

    RequestBody formBody = new FormEncodingBuilder().add("uid", value)

            .build();

    // Constant.KEY_TEL
    Request request = new Request.Builder().url(Constant.URL_SEARCH_USER).post(formBody)

            .build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Request arg0, IOException arg1) {

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    pd.dismiss();
                    Toast.makeText(AddContactActivity.this, "??", Toast.LENGTH_SHORT).show();

                }

            });
        }

        @Override
        public void onResponse(Response arg0) throws IOException {

            if (arg0.isSuccessful()) {
                String result = arg0.body().string();
                System.out.println("result--->" + result);
                final JSONObject json = JSONObject.parseObject(Constant.jsonTokener(result));

                if (json.getInteger("code") == 1000) {

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            pd.dismiss();

                        }

                    });

                    JSONObject userInfo = json.getJSONObject("user");

                    startActivity(new Intent(AddContactActivity.this, UserDetailActivity.class)
                            .putExtra("userInfo", userInfo.toJSONString()));

                } else {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT)
                                    .show();
                        }

                    });

                }

            } else {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        pd.dismiss();
                    }

                });
                throw new IOException("Unexpected code " + arg0);
            }

        }

    });

}

From source file:com.google.android.gcm.demo.app.DemoActivity.java

License:Apache License

private boolean registerToUniqush(String registrationId) throws IOException {
    RequestBody formBody = new FormEncodingBuilder().add("service", "ZenUI_PushService_5")
            .add("subscriber", "uniqush.client").add("pushservicetype", "gcm").add("regid", registrationId)
            .build();//from  ww  w  . ja v  a 2 s  .c o  m
    String url = "http://140.128.101.214:9898/subscribe";

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder().url(url).post(formBody).build();

    Response response = client.newCall(request).execute();
    return response.isSuccessful();
}

From source file:com.google.android.gcm.demo.app.DemoActivity.java

License:Apache License

private boolean registerToPushd(String registrationId) throws IOException {
    String host = "http://vps.semoncat.com/push";

    RequestBody formBody = new FormEncodingBuilder().add("proto", "gcm").add("token", registrationId)
            .add("lang", Locale.getDefault().toString()).add("timezone", TimeZone.getDefault().getID()).build();

    String url = host + "/subscribers";

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
            //.header("Authorization", getAuthHeader("SemonCat", "zoe80904"))
            .url(url).post(formBody).build();

    Response response = client.newCall(request).execute();
    if (response.isSuccessful()) {
        String id = new Gson().fromJson(response.body().string(), JsonObject.class).get("id").getAsString();

        Log.d(TAG, "Id:" + id);

        //subscriber
        RequestBody subscriberFormBody = new FormEncodingBuilder().add("ignore_message", "0").build();

        String subscriberUrl = host + "/subscriber/%s/subscriptions/zenui_help";

        Request subscriberRequest = new Request.Builder()
                //.header("Authorization", getAuthHeader("SemonCat", "zoe80904"))
                .url(String.format(subscriberUrl, id)).post(subscriberFormBody).build();

        Response subscriberResponse = client.newCall(subscriberRequest).execute();
        return subscriberResponse.isSuccessful();

    }//from  w w w .  ja  va 2s . c o  m
    return false;
}

From source file:com.gqp.duoduo.ui.activity.SearchGoodsForCheckActivity.java

private void getGoodsList(String input) {
    if (TextUtils.isEmpty(input)) {
        return;/*  ww w .j  av a 2s .co  m*/
    }
    showLoading("...");

    FormEncodingBuilder builder = new FormEncodingBuilder().add("page", "0").add("size", "65535");
    if (!TextUtils.isEmpty(isBarcode)) {
        builder.add("barcode", input);
        builder.add("goodsname", "");
    } else {
        builder.add("goodsname", input);
    }
    Request request = new Request.Builder().url(HttpUrl.QUERY_GOODS).post(builder.build())
            .addHeader("accept", "application/json").addHeader("dodomobile", String.valueOf(UUID.randomUUID()))
            .tag(System.currentTimeMillis()).build();

    compositeSubscription
            .add(HttpRequest.modelRequest(request, GoodsList.class).subscribe(new Subscriber<GoodsList>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    //                                showToast("");
                    dismissLoading();
                    if (e instanceof ErrorMessageException) {
                        if (App.getNetState()) {
                            reLogin();
                        } else {
                            showToast("??");
                        }
                    }
                    showToast(e.getMessage());
                }

                @Override
                public void onNext(GoodsList inventoryList) {
                    dismissLoading();
                    mList.clear();
                    int size = inventoryList.getRows().size();
                    search_result_listview.removeAllViews();
                    mList.addAll(inventoryList.getRows());

                    if (mList != null && mList.size() > 0) {
                        LayoutInflater inflater = LayoutInflater.from(SearchGoodsForCheckActivity.this);
                        int index = 0;
                        for (Goods entity : mList) {
                            View view = inflater.inflate(R.layout.search_goods_for_check_item, null);
                            SearchGoodsViewItemHolder holder = new SearchGoodsViewItemHolder(view);
                            holder.bind(entity, index);
                            search_result_listview.addView(view);

                            View divider = new View(SearchGoodsForCheckActivity.this);
                            divider.setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2));
                            divider.setBackgroundColor(Color.parseColor("#dddddd"));
                            search_result_listview.addView(divider);

                            index++;
                        }

                    }
                }
            }));
}

From source file:com.gqp.duoduo.ui.activity.SearchHisOrderActivity.java

private void getInventoryList(String input) {

    if (TextUtils.isEmpty(input)) {
        return;//  w  ww  . j ava2  s.c  om
    }
    //        try {
    //            SimpleDateFormat sf = new_version SimpleDateFormat("yyyyMMdd");
    //            Date date = sf.parse(input);
    //            SimpleDateFormat sf1 = new_version SimpleDateFormat("yyyy-MM-dd");
    //            input = sf1.format(date);
    //        }catch (Exception e){
    //            e.printStackTrace();
    //        }

    FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder().add("page", "0").add("size", "100");
    formEncodingBuilder.add("status", "4");
    formEncodingBuilder.add("customer", input);
    Request request = new Request.Builder().url(HttpUrl.ORDER_LIST_NEW).post(formEncodingBuilder.build())
            .addHeader("accept", "application/json").addHeader("dodomobile", String.valueOf(UUID.randomUUID()))
            .tag(System.currentTimeMillis()).build();

    compositeSubscription
            .add(HttpRequest.modelRequest(request, OrderList.class).subscribe(new Subscriber<OrderList>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    if (e instanceof ErrorMessageException) {
                        if (App.getNetState()) {
                            reLogin();
                        } else {
                            showToast("??");
                        }
                    }
                    //                                showToast(e.getMessage());
                }

                @Override
                public void onNext(OrderList inventoryList) {
                    int size = inventoryList.getRows().get(0).getPageList().size();
                    mList.clear();
                    mList.addAll(inventoryList.getRows().get(0).getPageList());
                    adapter.notifyDataSetChanged();

                }
            }));
}

From source file:com.gqp.duoduo.ui.activity.SearchHisSettlementActivity.java

private void getHisSettlementInfo(String input) {

    if (TextUtils.isEmpty(input)) {
        return;//w  w  w  .java 2s. c  o m
    }
    Request request = new Request.Builder().url(HttpUrl.QUERY_SETTLEMENT)
            .post(new FormEncodingBuilder().add("irdate", input).build())
            .addHeader("accept", "application/json").addHeader("dodomobile", String.valueOf(UUID.randomUUID()))
            .tag(System.currentTimeMillis()).build();

    compositeSubscription
            .add(HttpRequest.modelRequest(request, Settlement.class).subscribe(new Subscriber<Settlement>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    if (e instanceof ErrorMessageException) {
                        if (App.getNetState()) {
                            reLogin();
                        } else {
                            showToast("??");
                        }
                    }
                    showToast(e.getMessage());
                }

                @Override
                public void onNext(Settlement inventoryList) {

                    if (inventoryList != null) {
                        message = inventoryList.getMessage();
                        mList = inventoryList.getMessage().getSettelment();
                        getRealInCome(inventoryList.getMessage());
                        dataLayout.setVisibility(View.VISIBLE);
                        noDataLayout.setVisibility(View.GONE);

                        container.removeAllViews();

                        LayoutInflater inflater = LayoutInflater.from(SearchHisSettlementActivity.this);

                        View headerView = inflater.inflate(R.layout.common_item_hearder_layout, null);
                        ((TextView) headerView.findViewById(R.id.common_item_01)).setText("??");
                        ((TextView) headerView.findViewById(R.id.common_item_02)).setText("?");
                        headerView.setBackgroundResource(R.color.gray_whiter);
                        container.addView(headerView);

                        int index = 0;
                        for (Settlement.MarketSettleEntity marketModel : mList) {

                            View view = inflater.inflate(R.layout.common_item_layout, null);
                            ViewMarketItemHolder holder = new ViewMarketItemHolder(view);
                            holder.bind(marketModel, index);
                            container.addView(view);

                            View divider = new View(SearchHisSettlementActivity.this);
                            divider.setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2));
                            divider.setBackgroundColor(Color.parseColor("#DDDDDD"));
                            container.addView(divider);
                            index++;
                        }
                        View footerdivider = new View(SearchHisSettlementActivity.this);
                        footerdivider.setLayoutParams(
                                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));

                        footerdivider.setBackgroundColor(Color.parseColor("#ededed"));
                        container.addView(footerdivider);
                        int sIndex = 0;
                        List<CommonItem> tmpList = formatData(inventoryList.getMessage().getSettelmentTotal());
                        for (CommonItem commonItem : tmpList) {
                            View view = inflater.inflate(R.layout.common_item_hearder_layout, null);
                            ViewItemHolder holder = new ViewItemHolder(view);
                            holder.bind(commonItem, index);
                            container.addView(view);
                            View divider = new View(SearchHisSettlementActivity.this);
                            divider.setLayoutParams(
                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2));
                            divider.setBackgroundColor(Color.parseColor("#dddddd"));
                            container.addView(divider);
                            if (sIndex == 0) {
                                View footerView01 = new View(SearchHisSettlementActivity.this);
                                footerView01.setLayoutParams(
                                        new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));
                                footerView01.setBackgroundResource(R.color.gray_whiter);
                                container.addView(footerView01);
                            }
                            if (sIndex <= 2) {
                                if (sIndex == 2) {
                                    View footerView01 = new View(SearchHisSettlementActivity.this);
                                    footerView01.setLayoutParams(new LinearLayout.LayoutParams(
                                            ViewGroup.LayoutParams.MATCH_PARENT, 38));
                                    footerView01.setBackgroundResource(R.color.gray_whiter);
                                    container.addView(footerView01);
                                }
                            }
                            if (sIndex > 2 && sIndex <= 6) {
                                if (sIndex == 6) {
                                    View footerView01 = new View(SearchHisSettlementActivity.this);
                                    footerView01.setLayoutParams(new LinearLayout.LayoutParams(
                                            ViewGroup.LayoutParams.MATCH_PARENT, 38));
                                    footerView01.setBackgroundResource(R.color.gray_whiter);
                                    container.addView(footerView01);
                                }
                            }
                            sIndex++;
                        }

                    }
                }
            }));
}

From source file:com.gqp.duoduo.ui.activity.SearchInventoryActivity.java

private void getInventoryList(String input) {

    if (TextUtils.isEmpty(input)) {
        return;/*  w ww. j  a va2 s.  co  m*/
    }
    Request request = new Request.Builder().url(HttpUrl.REPOSITORY_LIST_QUERY + input)
            .post(new FormEncodingBuilder().add("", "").build()).addHeader("accept", "application/json")
            .addHeader("dodomobile", String.valueOf(UUID.randomUUID())).tag(System.currentTimeMillis()).build();

    compositeSubscription.add(
            HttpRequest.modelRequest(request, RepsitoryList.class).subscribe(new Subscriber<RepsitoryList>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    if (e instanceof ErrorMessageException) {
                        if (App.getNetState()) {
                            reLogin();
                        } else {
                            showToast("??");
                        }
                    }
                    //                                showToast(e.getMessage());
                }

                @Override
                public void onNext(RepsitoryList inventoryList) {
                    int size = inventoryList.getMessage().size();

                    mList.clear();

                    mList.addAll(inventoryList.getMessage());

                    adapter.notifyDataSetChanged();
                    //                                MarketList.MessageEntity.SuperMarketContentEntity rowsEntity = marketList.getMessage().getSuperMarketContent().get(i);

                }
            }));
}