use of okhttp3.FormBody in project Manhua by ag2s20150909.
the class API method getChapters.
public static String getChapters(String bookid) {
// &bid=320&sortType=ASC
FormBody.Builder buider = new FormBody.Builder();
buider.add("sortType", "ASC").add("bid", bookid);
//
FormBody formBody = APIheper.getFormBuider(buider).build();
// String url=host + "/api/recom/index";
String url = host + "/api/book/chapters";
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 drill by apache.
the class SimpleHttp method buildPostBody.
/**
* Accepts text from a post body in the format:<br>
* {@code key1=value1}<br>
* {@code key2=value2}
* <p>
* and creates the appropriate headers.
*
* @return FormBody.Builder The populated formbody builder
*/
private FormBody.Builder buildPostBody(String postBody) {
FormBody.Builder formBodyBuilder = new FormBody.Builder();
if (StringUtils.isEmpty(postBody)) {
return formBodyBuilder;
}
final Pattern postBodyPattern = Pattern.compile("^.+=.+$");
String[] lines = postBody.split("\\r?\\n");
for (String line : lines) {
// Otherwise ignore
if (postBodyPattern.matcher(line).find()) {
// Split into key/value
String[] parts = line.split("=");
formBodyBuilder.add(parts[0], parts[1]);
}
}
return formBodyBuilder;
}
use of okhttp3.FormBody in project Gradle-demo by Arisono.
the class OkhttpUtils method sendPostHttp.
/**
* post http
* @param url
* @param params
* @param tag
*/
public static void sendPostHttp(String url, Map<String, Object> params, String cookies, String tag) {
Builder paramBuilder = new FormBody.Builder();
if (!params.isEmpty()) {
Iterator<Map.Entry<String, Object>> entries = params.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Object> entry = entries.next();
paramBuilder.add(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
OkhttpUtils.println(tag + ":" + url);
RequestBody formBody = paramBuilder.build();
Request request = new Request.Builder().url(url).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", cookies).post(formBody).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String requestJson = OkhttpUtils.getResponseString(response);
RxBus.getInstance().send(tag + ":" + requestJson);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(call, e, this);
}
});
}
}
use of okhttp3.FormBody in project Gradle-demo by Arisono.
the class testUASApi method selectCardLog.
public static void selectCardLog(String date, String method) {
// {master=USOFTSYS, emcode=U0316, pageSize=100, sessionUser=U0316,
// condition=cl_emcode='U0316' and to_char(cl_time,'yyyy-MM-dd')='2017-03-03',
// sessionId=29DB60DE6E40D859B9169FE5013A8520, caller=CardLog, page=1, currentMaster=USOFTSYS}
String url = baseurl + "/mobile/oa/workdata.action";
RequestBody formBody = new FormBody.Builder().add("currentMaster", master).add("master", master).add("emcode", emcode).add("condition", "cl_emcode='U0316' and to_char(cl_time,'yyyy-MM-dd')='" + date + "'").add("caller", "CardLog").add("page", "1").add("sessionId", sessionId).build();
Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
try {
Response response = OkhttpUtils.client.newCall(request).execute();
OkhttpUtils.println(response.body().string());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// OkhttpUtils.client.newCall(request).enqueue(new Callback() {
//
// @Override
// public void onResponse(Call call, Response response)
// throws IOException {
// String result= OkhttpUtils.getResponseString(response);
// OkhttpUtils.println(result,OkhttpUtils.typeMiddle,method);
//
//
//
// }
//
// @Override
// public void onFailure(Call call, IOException e) {
// OkhttpUtils.onFailurePrintln(e);
// }
// });
//
}
use of okhttp3.FormBody in project Gradle-demo by Arisono.
the class testUASApi method addWorkReport.
/**
* 添加日报
*/
public static void addWorkReport() {
String url = baseurl + "mobile/addWorkReport.action";
RequestBody formBody = new FormBody.Builder().add("master", master).add("formStore", "{\"wd_experience\":\"\",\"wd_comment\":\"13.37一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三\",\"wd_empcode\":\"U0747\",\"wd_plan\":\"\"}").add("caller", "WorkDaily").add("sessionId", sessionId).build();
Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
OkhttpUtils.println(OkhttpUtils.getResponseString(response));
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(e);
}
});
}
Aggregations