use of okhttp3.FormBody in project Dxditor by kimi2009.
the class BridgeModel method getTrendData.
@Override
public void getTrendData(final ValueCallBack<String> callBack, final int position) {
if (Constants.testData) {
BridgeBean bridgeBean = new BridgeBean();
ArrayList<String> x = new ArrayList<String>();
for (int i = 0; i < 8; i++) {
x.add("03-2" + i + " 08:00");
}
bridgeBean.xData = x;
ArrayList<Float> f = new ArrayList<Float>();
if (position == 0) {
for (int i = 0; i < 8; i++) {
f.add(Float.parseFloat("2." + i));
}
} else if (position == 1) {
for (int i = 0; i < 8; i++) {
f.add(Float.parseFloat("1.0" + i));
}
;
} else if (position == 2) {
for (int i = 1; i < 9; i++) {
f.add(Float.parseFloat("0.8" + i));
}
}
bridgeBean.seriesData = f;
if (position == 0) {
bridgeBean.initValue = 2.3f;
} else if (position == 1) {
bridgeBean.initValue = 1.1f;
} else if (position == 2) {
bridgeBean.initValue = 0.8f;
}
callBack.onSuccess(gson.toJson(bridgeBean));
} else {
bridgeTrends = new ArrayList<BridgeTrend>();
// Form表单格式的参数传递
FormBody formBody = new FormBody.Builder().add("bridgeCode", bridgeWarnings.get(position).getBridgeCode()).add("monitotObjectCode", bridgeWarnings.get(position).getMonitorObjectCode()).add("monitorItemCode", bridgeWarnings.get(position).getMonitorItemCode()).add("storageTime", Constants.MONTH).build();
Request request = new Request.Builder().post(formBody).url(Constants.getAppBridgeMonthDisplacementInfo).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String res = response.body().string();
try {
JSONObject js = new JSONObject(res);
if (js.getBoolean("success")) {
bridgeTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<BridgeTrend>>() {
}.getType());
BridgeBean bridgeBean = new BridgeBean();
List<String> time = new ArrayList<>();
for (int i = 0; i < bridgeTrends.size(); i++) {
time.add(bridgeTrends.get(i).getStorageTime());
}
bridgeBean.xData = time;
List<Float> lineDatas = new ArrayList<>();
for (int i = 0; i < bridgeTrends.size(); i++) {
lineDatas.add(Float.parseFloat(bridgeTrends.get(i).getValue()));
}
bridgeBean.seriesData = lineDatas;
bridgeBean.initValue = Float.parseFloat(bridgeWarnings.get(position).getInitValue());
callBack.onSuccess(gson.toJson(bridgeBean));
} else {
callBack.onFail("01");
}
} catch (Exception e) {
callBack.onFail("01");
e.printStackTrace();
}
}
});
}
}
use of okhttp3.FormBody in project MVPFrames by RockyQu.
the class ParameterInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
HashMap<String, Object> parameters = callback.parameters();
if (parameters != null && parameters.size() != 0) {
if (request.method().equals("GET")) {
// 为GET方式统一添加请求参数
HttpUrl.Builder modifiedUrl = request.url().newBuilder().scheme(request.url().scheme()).host(request.url().host());
if (parameters != null && parameters.size() != 0) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
modifiedUrl.addQueryParameter(entry.getKey(), entry.getValue().toString());
}
}
request = request.newBuilder().method(request.method(), request.body()).url(modifiedUrl.build()).build();
} else if (request.method().equals("POST")) {
// 为POST方式统一添加请求参数
if (request.body() instanceof FormBody) {
FormBody.Builder body = new FormBody.Builder();
if (parameters != null && parameters.size() != 0) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
body.addEncoded(entry.getKey(), entry.getValue().toString());
}
}
body.build();
FormBody oldBody = (FormBody) request.body();
if (oldBody != null && oldBody.size() != 0) {
for (int i = 0; i < oldBody.size(); i++) {
body.addEncoded(oldBody.encodedName(i), oldBody.encodedValue(i));
}
}
request = request.newBuilder().post(body.build()).build();
}
}
}
return chain.proceed(request);
}
use of okhttp3.FormBody in project Manhua by ag2s20150909.
the class API method getCateDetail.
public static String getCateDetail(int class_id, int page, int pageSize) {
// POST /api/book/cate-detail HTTP/1.1
// &pageSize=20&sortType=popu&page=1&classId=638
// sortType popu,update
FormBody.Builder buider = new FormBody.Builder();
buider.add("classId", class_id + "");
buider.add("sortType", "popu");
buider.add("page", page + "");
buider.add("pageSize", pageSize + "");
//
FormBody formBody = APIheper.getFormBuider(buider).build();
String url = host + "/api/book/cate-detail";
Request request = new Request.Builder().post(formBody).url(url).build();
try {
Response response = APP.getOkhttpClient().newCall(request).execute();
if (response.isSuccessful()) {
return new JSONObject(response.body().string()).toString(4);
} else {
return "error:" + response.message() + " errorcode:" + response.code();
}
} catch (Exception e) {
return "error:" + e.getMessage();
}
}
use of okhttp3.FormBody in project Manhua by ag2s20150909.
the class API method search_1.
public static String search_1(String kw, int page, int pageSize) {
// POST /api/book/search HTTP/1.1
// &pageSize=20&keyword
FormBody.Builder buider = new FormBody.Builder();
buider.add("keyword", kw);
buider.add("page", page + "");
buider.add("pageSize", pageSize + "");
//
FormBody formBody = APIheper.getFormBuider(buider).build();
String url = host + "/api/book/search";
Request request = new Request.Builder().post(formBody).url(url).build();
try {
Response response = APP.getOkhttpClient().newCall(request).execute();
if (response.isSuccessful()) {
return new JSONObject(response.body().string()).toString();
} else {
return "error:" + response.message() + " errorcode:" + response.code();
}
} catch (Exception e) {
return "error:" + e.getMessage();
}
}
use of okhttp3.FormBody in project Manhua by ag2s20150909.
the class API method getContents.
// /api/book/contents
public static String getContents(String bid, String cid) {
// &bid=320&sortType=ASC
FormBody.Builder buider = new FormBody.Builder();
buider.add("cid", cid).add("bid", bid);
//
FormBody formBody = APIheper.getFormBuider(buider).build();
String url = host + "/api/book/contents";
Request request = new Request.Builder().post(formBody).url(url).build();
try {
Response response = APP.getCachehttpClient().newCall(request).execute();
if (response.isSuccessful()) {
String json = new JSONObject(response.body().string()).toString();
FileTool.writeFiles("chapter", bid + "_" + cid + ".json", json);
return json;
} else {
return "error:" + response.message() + " errorcode:" + response.code();
}
} catch (Exception e) {
return "error:" + e.getMessage();
}
}
Aggregations