List of usage examples for com.squareup.okhttp FormEncodingBuilder FormEncodingBuilder
FormEncodingBuilder
From source file:com.quwu.xinwo.home_page.DigitalActivity.java
/** * ???/* w ww. ja v a2s . c om*/ * */ public static String MyDoPost(String url, String normal_use, String warranty_period, String no_repair, String brand_new, String jingdong, String mainland_licensed, String since, String good_region, String city_region, String small_area, String twolevel_id, String three_id, String sortorder_id, String goods_lprice, String goods_hprice, String buy_userid, int pageNow, int pageSize) { OkHttpClient mOkHttpClient = new OkHttpClient(); RequestBody formBody = new FormEncodingBuilder().add("normal_use", normal_use) .add("warranty_period", warranty_period).add("no_repair", no_repair).add("brand_new", brand_new) .add("jingdong", jingdong).add("mainland_licensed", mainland_licensed).add("since", since) .add("good_region", good_region).add("city_region", city_region).add("small_area", small_area) .add("twolevel_id", twolevel_id).add("three_id", three_id).add("sortorder_id", sortorder_id) .add("goods_lprice", goods_lprice).add("goods_hprice", goods_hprice).add("buy_userid", buy_userid) .add("pageNow", String.valueOf(pageNow)).add("pageSize", String.valueOf(pageSize)).build(); // header(name, value) // ?name?value?? addHeader(name, value) // ?? Request request = new Request.Builder().url(url).header("User-Agent", "OkHttp Headers.java") .addHeader("Accept", "application/json; q=0.5") .addHeader("Accept", "application/vnd.github.v3+json").post(formBody).build(); Response response; try { response = mOkHttpClient.newCall(request).execute(); if (response.isSuccessful()) { String body = response.body().string(); return body; } } catch (IOException e) { e.printStackTrace(); } // execute return null; }
From source file:com.rsu.nuttanun.testdrivingvlicense.ConfirmScoreActivity.java
public void clickOKConfirm(View view) { String urlPHP = "http://swiftcodingthai.com/toey/add_score.php"; OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = new FormEncodingBuilder().add("isAdd", "true").add("id_login", loginStrings[0]) .add("Date", dateString).add("Score", scoreString).build(); Request.Builder builder = new Request.Builder(); Request request = builder.url(urlPHP).post(requestBody).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override//ww w . j a va 2 s . c o m public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { Intent intent = new Intent(ConfirmScoreActivity.this, ScoreListView.class); intent.putExtra("login", loginStrings); startActivity(intent); finish(); } }); }
From source file:com.rsu.nuttanun.testdrivingvlicense.ScoreListView.java
private void createListView() { String urlPHP = "http://swiftcodingthai.com/toey/get_score_where.php"; OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = new FormEncodingBuilder().add("isAdd", "true").add("id_login", loginStrings[0]) .build();/*from w w w . j a v a 2s. com*/ Request.Builder builder = new Request.Builder(); Request request = builder.url(urlPHP).post(requestBody).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { String strResponse = response.body().string(); Log.d("10AugV2", "strResponse ==>" + strResponse); try { JSONArray jsonArray = new JSONArray(strResponse); String[] dateStrings = new String[jsonArray.length()]; String[] scoreStrings = new String[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); dateStrings[i] = jsonObject.getString("Date"); scoreStrings[i] = jsonObject.getString("Score") + " ?"; } //for CoaurseAdapter coaurseAdapter = new CoaurseAdapter(ScoreListView.this, 1, dateStrings, scoreStrings); listView.setAdapter(coaurseAdapter); } catch (Exception e) { e.printStackTrace(); } } // onRespose }); }
From source file:com.rsu.nuttanun.testdrivingvlicense.SignUpActivity.java
private void upLoadNewUser() { OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = new FormEncodingBuilder().add("isAdd", "true").add("Name", nameString) .add("Surname", surnameString).add("Age", ageString).add("User", userString) .add("Password", passwordString).build(); Request.Builder builder = new Request.Builder(); Request request = builder.url(urlPHP).post(requestBody).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override/*from w w w . j a va 2s.co m*/ public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { finish(); } }); }
From source file:com.sonaive.v2ex.sync.api.Api.java
License:Open Source License
public Bundle sync(HttpMethod httpMethod) { OkHttpClient okHttpClient = new OkHttpClient(); Request request = null;/* w w w . j a va 2s. c om*/ if (httpMethod == HttpMethod.GET) { request = new Request.Builder().url(mUrl).build(); } else { String json = mArguments.getString(ARG_API_PARAMS); HashMap params = new Gson().fromJson(json, HashMap.class); FormEncodingBuilder formBodyBuilder = new FormEncodingBuilder(); for (Map.Entry<String, String> entry : ((HashMap<String, String>) params).entrySet()) { formBodyBuilder.add(entry.getKey(), entry.getValue()); } RequestBody formBody = formBodyBuilder.build(); request = new Request.Builder().url(mUrl).post(formBody).build(); } try { Response response = okHttpClient.newCall(request).execute(); if (response != null && response.code() == 200) { LOGD(TAG, "Request: " + mUrl + ", server returned HTTP_OK, so fetching was successful."); mArguments.putString(Api.ARG_RESULT, response.body().string()); return mArguments; } else if (response != null && response.code() == 403) { LOGW(TAG, "Request: " + mUrl + ", Server returned 403, fetching was failed."); } else { LOGW(TAG, "Request: " + mUrl + ", Fetching was failed. Unknown reason"); } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.urswolfer.gerrit.client.rest.http.GerritRestClient.java
License:Apache License
/** * Handles LDAP auth (but not LDAP_HTTP) which uses a HTML form. *//*from ww w . ja v a2s .c o m*/ private Optional<String> tryGerritHttpFormAuth(OkHttpClient client) throws IOException { if (!authData.isLoginAndPasswordAvailable()) { return Optional.absent(); } String loginUrl = authData.getHost() + "/login/"; RequestBody formBody = new FormEncodingBuilder().add("username", authData.getLogin()) .add("password", authData.getPassword()).build(); Request.Builder builder = new Request.Builder().url(loginUrl).post(formBody); Response loginResponse = httpRequestExecutor.execute(client, builder); return extractGerritAuth(loginResponse); }
From source file:com.votzapp.app.RegistrationIntentService.java
License:Open Source License
/** * Persist registration to third-party servers. * * Modify this method to associate the user's GCM registration token with any server-side account * maintained by your application.// w w w . ja v a 2s .c om * * @param token The new token. */ private void sendRegistrationToServer(String token, String email) { // Adding custom implementation OkHttpClient client = new OkHttpClient(); //Sending both GCM_TOKEN and EMAIL to the server RequestBody requestBody = new FormEncodingBuilder().add(KEY_TOKEN, token).add(EMAIL, email).build(); Request request = new Request.Builder().url(REGISTER_URL).post(requestBody).build(); try { Response response = client.newCall(request).execute(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.wialon.remote.OkSdkHttpClient.java
License:Apache License
private static RequestBody paramsMapToRequestBody(Map<String, String> params) { if (params != null) { FormEncodingBuilder builder = new FormEncodingBuilder(); for (Map.Entry<String, String> entry : params.entrySet()) builder.add(entry.getKey(), entry.getValue()); return builder.build(); }//w w w . j a v a 2 s .c o m return null; }
From source file:com.xing.api.Oauth1SigningInterceptorTest.java
License:Apache License
@Test public void withBody() throws IOException { RequestBody body = new FormEncodingBuilder() // .add("status", "Hello Ladies + Gentlemen, a signed OAuth request!") // .build();// w ww .j a v a 2 s .c o m Request request = new Request.Builder() // .url("https://api.twitter.com/1/statuses/update.json?include_entities=true") // .post(body) // .build(); Request signed = oauth1.signRequest(request); assertAuthHeader(signed, "tnnArxj06cWHq44gCs1OSKk%2FjLY%3D"); }
From source file:com.yingke.shengtai.adapter.ChatAllHistoryAdapter.java
License:Open Source License
public void postRequest(final TextView text, final String userName, final Map<String, String> map) { FormEncodingBuilder builder = new FormEncodingBuilder(); for (Map.Entry<String, String> entry : map.entrySet()) { builder.add(entry.getKey(), entry.getValue()); }//from w w w.j a va 2 s. co m RequestBody formBody = builder.build(); Request request = new Request.Builder().url(IApi.URL_IMID_NAME).header("User-Agent", "OkHttp Headers.java") .addHeader("Accept", "application/json").addHeader("Content-Type", "application/json;charset=utf-8") .addHeader("Content-Length", "length").post(formBody).build(); RequestManager.getOkHttpClient().newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { String json = response.body().string(); ImidToNickNameData data = JosnUtil.gson.fromJson(json, new TypeToken<ImidToNickNameData>() { }.getType()); if (data != null && TextUtils.equals("1", "1")) { try { User user = new User(); user.setNick(data.getDetaillist().get(0).getDisplayname()); user.setUsername(data.getDetaillist().get(0).getImid()); user.setSex(data.getDetaillist().get(0).getSex()); userDao.saveContactsss(user); UIHandler.sendEmptyMessage(0); } catch (Exception e) { } } } } }); }