Java Code Examples for com.squareup.okhttp.FormEncodingBuilder#add()

The following examples show how to use com.squareup.okhttp.FormEncodingBuilder#add() . 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: BaseHttp.java    From MousePaint with MIT License 6 votes vote down vote up
protected void basePost(String url, Map<String, String> params, CallbackListener<T> listener)
{
    if (params == null) {
       baseGet(url,listener);return;
    }
    FormEncodingBuilder builder = new FormEncodingBuilder();
    Set<Map.Entry<String, String>> entrySet = params.entrySet();
    for (Map.Entry<String, String> entry : entrySet) {
        builder.add(entry.getKey(), entry.getValue());
    }
    RequestBody requestBody = builder.build();
    Request request = new Request.Builder()
            .url(url)
            .post(requestBody)
            .tag(url)
            .build();
    doRequest(request, listener);
}
 
Example 2
Source File: OkHttpProxy.java    From JianDan_OkHttp with Apache License 2.0 6 votes vote down vote up
public static Call post(String url, Map<String, String> params, Object tag, OkHttpCallback responseCallback) {

        Request.Builder builder = new Request.Builder().url(url);
        if (tag != null) {
            builder.tag(tag);
        }

        FormEncodingBuilder encodingBuilder = new FormEncodingBuilder();

        if (params != null && params.size() > 0) {
            for (String key : params.keySet()) {
                encodingBuilder.add(key, params.get(key));
            }
        }

        RequestBody formBody = encodingBuilder.build();
        builder.post(formBody);

        Request request = builder.build();
        Call call = getInstance().newCall(request);
        call.enqueue(responseCallback);
        return call;
    }
 
Example 3
Source File: PostFormRequest.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
private void addParams(FormEncodingBuilder builder)
{
    if (params == null || params.isEmpty())
    {
        builder.add("1", "1");
        return;
    }

    for (String key : params.keySet())
    {
        builder.add(key, params.get(key));
    }
}
 
Example 4
Source File: ApiClient.java    From nifi-api-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * Build a form-encoding request body with the given form parameters.
 *
 * @param formParams Form parameters in the form of Map
 * @return RequestBody
 */
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
    FormEncodingBuilder formBuilder  = new FormEncodingBuilder();
    for (Entry<String, Object> param : formParams.entrySet()) {
        formBuilder.add(param.getKey(), parameterToString(param.getValue()));
    }
    return formBuilder.build();
}
 
Example 5
Source File: ApiClient.java    From ariADDna with Apache License 2.0 5 votes vote down vote up
/**
 * Build a form-encoding request body with the given form parameters.
 *
 * @param formParams Form parameters in the form of Map
 * @return RequestBody
 */
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
    FormEncodingBuilder formBuilder = new FormEncodingBuilder();
    for (Entry<String, Object> param : formParams.entrySet()) {
        formBuilder.add(param.getKey(), parameterToString(param.getValue()));
    }
    return formBuilder.build();
}
 
Example 6
Source File: OkHttpPostRequest.java    From meiShi with Apache License 2.0 5 votes vote down vote up
private void addParams(FormEncodingBuilder builder, Map<String, String> params)
{
    if (builder == null)
    {
        throw new IllegalArgumentException("builder can not be null .");
    }

    if (params != null && !params.isEmpty())
    {
        for (String key : params.keySet())
        {
            builder.add(key, params.get(key));
        }
    }
}
 
Example 7
Source File: OkHttpUtils.java    From SimpleNews with Apache License 2.0 5 votes vote down vote up
private Request buildPostRequest(String url, List<Param> params) {
    FormEncodingBuilder builder = new FormEncodingBuilder();
    for (Param param : params) {
        builder.add(param.key, param.value);
    }
    RequestBody requestBody = builder.build();
    return new Request.Builder().url(url).post(requestBody).build();
}
 
Example 8
Source File: TransactionsFragment.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
private RequestBody buildInitialRequestBody() {
    FormEncodingBuilder postdata = new FormEncodingBuilder();
    if (TransactionType.Bevo.equals(mType)) {
        postdata.add("sRequestSw", "B");
    } else if (TransactionType.Dinein.equals(mType)) {
        postdata.add("rRequestSw", "B");
    }
    return postdata.build();
}
 
Example 9
Source File: OkHttpHelper.java    From ImitateTaobaoApp with Apache License 2.0 4 votes vote down vote up
private RequestBody builderFormData(Map<String,String> params){


        FormEncodingBuilder builder = new FormEncodingBuilder();

        if(params !=null){

            for (Map.Entry<String,String> entry :params.entrySet() ){

                builder.add(entry.getKey(),entry.getValue());
            }


            String token = CniaoApplication.getInstance().getToken();
            if (!TextUtils.isEmpty(token)) {
                builder.add("token", token);
            }
        }

        return  builder.build();

    }