use of com.reprezen.kaizen.oasparser.model3.RequestBody in project AndroidFastDevFrame by linglongxin24.
the class HttpRequest method getRequestBody.
private String getRequestBody(MultipartBody.Part part) {
Class<?> personType = part.getClass();
// 访问私有属性
Field field = null;
try {
field = personType.getDeclaredField("body");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
field.setAccessible(true);
try {
RequestBody requestBody = (RequestBody) field.get(part);
MediaType contentType = requestBody.contentType();
if (contentType.type().equals("multipart")) {
Buffer buffer = new Buffer();
requestBody.writeTo(buffer);
Charset UTF8 = Charset.forName("UTF-8");
Charset charset = contentType.charset(UTF8);
return buffer.readString(charset);
} else if (contentType.type().equals("image")) {
return convertFileSize(requestBody.contentLength());
// Class<?> requestBodyClass = requestBody.getClass();
//
// //访问私有属性
// Field fileRequestBodyClass = null;
// try {
// fileRequestBodyClass = requestBodyClass.getDeclaredField("file");
//
//
// fileRequestBodyClass.setAccessible(true);
// File file = (File) fileRequestBodyClass.get(requestBody);
// Logger.d("file=" + file.getPath());
// } catch (NoSuchFieldException e) {
// e.printStackTrace();
// } catch (Exception e) {
// e.printStackTrace();
// }
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project NASABot by SniperNoob95.
the class DBClient method issuePutRequest.
public boolean issuePutRequest(String path, JSONObject payload) {
try {
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), payload.toString());
Request request = new Request.Builder().url(url + path).put(requestBody).build();
Response response = httpClient.newCall(request).execute();
if (response.code() != 201) {
response.close();
return false;
}
response.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project NASABot by SniperNoob95.
the class DBClient method issuePostRequest.
public boolean issuePostRequest(String path, JSONObject payload) {
try {
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), payload.toString());
Request request = new Request.Builder().url(url + path).post(requestBody).build();
Response response = httpClient.newCall(request).execute();
if (response.code() != 201) {
response.close();
return false;
}
response.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project NASABot by SniperNoob95.
the class TopGGClient method setStats.
private static void setStats(OkHttpClient httpClient, int serverCount) {
try {
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new JSONObject().put("server_count", serverCount).toString());
Request request = new Request.Builder().url(url + "/stats").method("POST", requestBody).addHeader("Authorization", "Bearer " + token).build();
Response response = httpClient.newCall(request).execute();
response.close();
} catch (Exception e) {
ErrorLogging.handleError("TopGGClient", "setStats", "Cannot set stats.", e);
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project AndroidFastDevFrame by linglongxin24.
the class RequestParameter method getFilePartMap.
/**
* 获取文件数组组装后的参数
*
* @param key parameter_key
* @param files 要上传的文件集合
* @return
*/
public static Map<String, RequestBody> getFilePartMap(String key, List<File> files) {
Map<String, RequestBody> paramsMap = new ArrayMap<>();
for (int i = 0; i < files.size(); i++) {
File file = files.get(i);
RequestBody fileBody = RequestBody.create(MediaType.parse("image/png"), file);
paramsMap.put(key + "\"; filename=\"" + file.getName(), fileBody);
}
return paramsMap;
}
Aggregations