List of usage examples for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder
FormEncodingBuilder
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
License:Apache License
/** * Build form body to be passed to access token * * @param refreshToken code from authorization process * @return RequestBody//from w ww.ja v a 2 s . c o m */ public static RequestBody getRefreshTokenBody(String refreshToken) { return new FormEncodingBuilder().addEncoded("grant_type", "refresh_token") .addEncoded("refresh_token", refreshToken).addEncoded("client_id", CLIENT_ID) .addEncoded("client_secret", CLIENT_SECRET).build(); }
From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java
License:Apache License
@Override public void logout(@NonNull Callback callback) { RequestBody body = new FormEncodingBuilder().add("client_id", CLIENT_ID).add("client_secret", CLIENT_SECRET) .add("token", mAccessToken).build(); Request request = new Request.Builder().url(REVOKE_URL).post(body).build(); mHttpClient.newCall(request).enqueue(callback); }
From source file:com.he5ed.lib.cloudprovider.apis.DropboxApi.java
License:Apache License
/** * Build form body to be passed to access token * * @param authCode code from authorization process * @return RequestBody//w w w . ja va 2 s. c o m */ public static RequestBody getAccessTokenBody(String authCode) { return new FormEncodingBuilder().addEncoded("grant_type", "authorization_code").addEncoded("code", authCode) .addEncoded("client_id", CLIENT_ID).addEncoded("client_secret", CLIENT_SECRET) .addEncoded("redirect_uri", REDIRECT_URL).build(); }
From source file:com.hileone.restretrofit.request.RequestBuilder.java
License:Apache License
RequestBuilder(String method, HttpUrl baseUrl, String relativeUrl, Headers headers, MediaType contentType, boolean hasBody, boolean isFormEncoded, boolean isMultipart) { this.method = method; this.baseUrl = baseUrl; this.relativeUrl = relativeUrl; this.requestBuilder = new Request.Builder(); this.contentType = contentType; this.hasBody = hasBody; if (headers != null) { requestBuilder.headers(headers); }//from w w w. j a va 2 s . com if (isFormEncoded) { // Will be set to 'body' in 'build'. formEncodingBuilder = new FormEncodingBuilder(); } else if (isMultipart) { // Will be set to 'body' in 'build'. multipartBuilder = new MultipartBuilder(); multipartBuilder.type(MultipartBuilder.FORM); } }
From source file:com.hippo.nimingban.client.ConvertEngine.java
License:Apache License
public static Call prepareConvert(OkHttpClient okHttpClient, String config, String content) { RequestBody formBody = new FormEncodingBuilder().add("config", config).add("content", content).build(); String url = URL;//from ww w . j av a 2 s . c o m Log.d(TAG, url); Request request = new GoodRequestBuilder(url).post(formBody).build(); return okHttpClient.newCall(request); }
From source file:com.hippo.nimingban.client.DiscEngine.java
License:Apache License
public static String weiyun(OkHttpClient okHttpClient, String url) throws IOException { String body;//from www .ja v a 2 s.co m Matcher matcher; body = okHttpClient.newCall(new Request.Builder().url(url).build()).execute().body().string(); matcher = PATTERN_WEIYUN_1.matcher(body); if (!matcher.find()) { throw new IOException("Can't get url"); } body = okHttpClient.newCall(new Request.Builder().url(URL_WEIYUN_OUTLINK) .post(new FormEncodingBuilder().add("data", getWeiyunPostJson(matcher.group(1))).build()).build()) .execute().body().string(); matcher = PATTERN_WEIYUN_2.matcher(body); if (matcher.find()) { return matcher.group(1); } else { throw new IOException("Can't get url"); } }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.core.internal.BaseRequest.java
License:Apache License
/** * Send this resource request asynchronously, with the given form parameters as the request body. * This method will set the content type header to "application/x-www-form-urlencoded". * * @param formParameters The parameters to put in the request body * @param listener The listener whose onSuccess or onFailure methods will be called when this request finishes. */// w w w. j a va2 s .c o m protected void send(Map<String, String> formParameters, ResponseListener listener) { FormEncodingBuilder formBuilder = new FormEncodingBuilder(); for (Map.Entry<String, String> param : formParameters.entrySet()) { formBuilder.add(param.getKey(), param.getValue()); } RequestBody body = formBuilder.build(); sendRequest(listener, body); }
From source file:com.ibm.watson.developer_cloud.http.RequestBuilder.java
License:Open Source License
/** * Builds a request with the given set of parameters and files. * /*from w ww. j a v a2 s .c om*/ * * @return HTTP request, prepared to be executed */ public Request build() { final Builder builder = new Request.Builder(); // URL builder.url(toUrl()); // POST/PUT require a body so send an empty body if the actual is null RequestBody requestBody = body; if (body == null) requestBody = RequestBody.create(null, new byte[0]); if (!formParams.isEmpty()) { final FormEncodingBuilder formBody = new FormEncodingBuilder(); for (final NameValue param : formParams) { final String value = param.getValue() != null ? param.getValue() : ""; formBody.add(param.getName(), value); } requestBody = formBody.build(); } // accept application/json by default builder.addHeader(HttpHeaders.ACCEPT, HttpMediaType.APPLICATION_JSON); if (!headers.isEmpty()) { for (final NameValue header : headers) { builder.addHeader(header.getName(), header.getValue()); } } switch (method) { case GET: builder.get(); break; case POST: builder.post(requestBody); break; case PUT: builder.put(requestBody); break; case DELETE: builder.delete(requestBody); break; } return builder.build(); }
From source file:com.kkbox.toolkit.internal.api.APIRequest.java
License:Apache License
public void addPostParam(String key, String value) { if (requestBodyBuilder == null) { requestBodyBuilder = new FormEncodingBuilder(); }/*from w ww.j a v a 2 s . c o m*/ requestBodyBuilder.add(key, value); }
From source file:com.lidroid.xutils.HttpUtils.java
License:Apache License
@NonNull private RequestBody buildFormRequestBody(RequestParams params) { if (params != null) { List<NameValuePair> bodyParams = params.getBodyParams(); if (bodyParams != null) { FormEncodingBuilder builder = new FormEncodingBuilder(); for (NameValuePair param : params.getBodyParams()) { builder.add(param.getName(), param.getValue()); }/*from w w w . jav a2 s . c om*/ return builder.build(); } HttpEntity entity = params.getEntity(); if (entity != null) { try { String body = InputStreamToString(entity.getContent(), "utf-8"); return RequestBody.create(MediaType.parse("application/javascript"), body); } catch (Exception ex) { LogUtil.e(ex.getMessage()); } } } return RequestBody.create(MediaType.parse("application/javascript"), ""); }