com.squareup.okhttp.FormEncodingBuilder Java Examples

The following examples show how to use com.squareup.okhttp.FormEncodingBuilder. 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: RefreshAccessTokenTask.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {

    RequestBody requestBody = new FormEncodingBuilder()
            .add("refresh_token", mRefreshToken)
            .add("client_id", mClientId)
            .add("client_secret", "ADD_YOUR_CLIENT_SECRET")
            .add("grant_type", "refresh_token")
            .build();
    final Request request = new Request.Builder()
            .url(Utils.ACCESS_TOKEN_URL)
            .post(requestBody)
            .build();
    mOkHttpClient.newCall(request).enqueue(new HttpCallback(mCallBack));
    return null;
}
 
Example #2
Source File: RequestAccessTokenTask.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {

    RequestBody requestBody = new FormEncodingBuilder()
            .add("grant_type", "authorization_code")
            .add("client_id", mClientId)
            .add("client_secret", "ADD_YOUR_CLIENT_SECRET")
            .add("redirect_uri","")
            .add("code", mCode)
            .build();
    final Request request = new Request.Builder()
            .url(url)
            .post(requestBody)
            .build();
    mOkHttpClient.newCall(request).enqueue(new HttpCallback(mCallBack));
    return null;
}
 
Example #3
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 #4
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 #5
Source File: OkHttpPostRequest.java    From meiShi with Apache License 2.0 6 votes vote down vote up
@Override
protected RequestBody buildRequestBody()
{
    validParams();
    RequestBody requestBody = null;


    switch (type)
    {
        case TYPE_PARAMS:
            FormEncodingBuilder builder = new FormEncodingBuilder();
            addParams(builder, params);
            requestBody = builder.build();
            break;
        case TYPE_BYTES:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, bytes);
            break;
        case TYPE_FILE:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, file);
            break;
        case TYPE_STRING:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STRING, content);
            break;
    }
    return requestBody;
}
 
Example #6
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 #7
Source File: HttpClient.java    From wind-im with Apache License 2.0 5 votes vote down vote up
static String postKV(String url) throws IOException {

		RequestBody formBody = new FormEncodingBuilder().add("platform", "android").add("name", "bug").build();

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

		Response response = client.newCall(request).execute();
		System.out.println("post KV response =" + response.isSuccessful());
		if (response.isSuccessful()) {
			return response.body().string();
		} else {
			throw new IOException("Unexpected code " + response);
		}
	}
 
Example #8
Source File: AuthCookie.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
protected Request buildLoginRequest() {
    String user = settings.getString("eid", "error");
    String pw = UTilitiesApplication.getInstance().getSecurePreferences()
            .getString("password", "error");

    RequestBody requestBody = new FormEncodingBuilder()
            .add(userNameKey, user)
            .add(passwordKey, pw)
            .build();
    return new Request.Builder()
            .url(url)
            .post(requestBody)
            .build();
}
 
Example #9
Source File: MainActivity.java    From androiddevice.info with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void submit() {
    LinearLayout alertLayout = (LinearLayout)LayoutInflater.from(MainActivity.this).inflate(R.layout.sending_alert,null);
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setCancelable(false).setView(alertLayout).setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    mAlertDialog = builder.show();
    //Button isn't null after show
    Button button = mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    button.setBackgroundResource(R.drawable.black_background_state);
    button.setTextColor(MainActivity.this.getResources().getColor(android.R.color.white));

    if(hasBeenSubmitted()) {
        ((TextView)mAlertDialog.findViewById(android.R.id.text1)).setText(R.string.alreadySent);
        mAlertDialog.findViewById(R.id.sending_progressbar).setVisibility(View.GONE);
        button.setEnabled(true);
    } else {
        button.setEnabled(false);

        final JSONObject deviceInformation = DeviceInformation.getInstance().getDeviceInformation();
        if(null != mDeviceName && 0 != mDeviceName.length()) {
            try {
                deviceInformation.put("name", mDeviceName);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        RequestBody formBody = new FormEncodingBuilder().add("device", deviceInformation.toString()).build();
        Request request = new Request.Builder().url(getString(R.string.submit)).addHeader("User-Agent", "APP").post(formBody).build();
        client.newCall(request).enqueue(new HTTPCallback(this.getApplication()));
    }
}
 
Example #10
Source File: ConnectionProvider.java    From yahnac with Apache License 2.0 5 votes vote down vote up
public Request replyToCommentRequest(String itemId, String commentId, String comment, String hmac) {
    RequestBody requestBody = (new FormEncodingBuilder())
            .add("parent", commentId)
            .add("goto", (new StringBuilder()).append("item?id=").append(itemId).toString())
            .add("text", comment)
            .add("hmac", hmac)
            .build();

    return createAuthRequest(requestBody);
}
 
Example #11
Source File: ConnectionProvider.java    From yahnac with Apache License 2.0 5 votes vote down vote up
public Request commentOnStoryRequest(String itemId, String comment, String hmac) {
    RequestBody requestBody = (new FormEncodingBuilder())
            .add("parent", itemId)
            .add("goto", (new StringBuilder()).append("item?id=").append(itemId).toString())
            .add("text", comment)
            .add("hmac", hmac)
            .build();

    return createAuthRequest(requestBody);
}
 
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: HttpClient.java    From openzaly with Apache License 2.0 5 votes vote down vote up
static String postKV(String url) throws IOException {

		RequestBody formBody = new FormEncodingBuilder().add("platform", "android").add("name", "bug").build();

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

		Response response = client.newCall(request).execute();
		System.out.println("post KV response =" + response.isSuccessful());
		if (response.isSuccessful()) {
			return response.body().string();
		} else {
			throw new IOException("Unexpected code " + response);
		}
	}
 
Example #18
Source File: HttpClient.java    From openzaly with Apache License 2.0 5 votes vote down vote up
static String postKV(String url) throws IOException {

		RequestBody formBody = new FormEncodingBuilder().add("platform", "android").add("name", "bug").build();

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

		Response response = client.newCall(request).execute();
		System.out.println("post KV response =" + response.isSuccessful());
		if (response.isSuccessful()) {
			return response.body().string();
		} else {
			throw new IOException("Unexpected code " + response);
		}
	}
 
Example #19
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();

    }