feat:增加一个表单提交方法
This commit is contained in:
@@ -57,6 +57,14 @@ public class OkHttpUtil {
|
||||
return ResponseBody.create(MediaType.parse("application/json; charset=utf-8"), json);
|
||||
}
|
||||
|
||||
public static FormBody ofFormResponse(Map<String, String> form) {
|
||||
FormBody.Builder formBuilder = new FormBody.Builder();
|
||||
for (String key : form.keySet()) {
|
||||
formBuilder.add(key, form.get(key));
|
||||
}
|
||||
return formBuilder.build();
|
||||
}
|
||||
|
||||
public static MultipartBody.Builder ofMultipartBody(File file) {
|
||||
return new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
@@ -98,16 +106,12 @@ public class OkHttpUtil {
|
||||
// Post请求
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static String post(String urlString, Map<String, String> paramMap) {
|
||||
return post(urlString, paramMap, OkHttpConfig.GLOBAL_TIMEOUT);
|
||||
public static String post(String urlString, Map<String, String> formMap) {
|
||||
return post(urlString, formMap, OkHttpConfig.GLOBAL_TIMEOUT);
|
||||
}
|
||||
|
||||
public static String post(String urlString, Map<String, String> paramMap, int timeout) {
|
||||
FormBody.Builder formBuilder = new FormBody.Builder();
|
||||
for (String key : paramMap.keySet()) {
|
||||
formBuilder.add(key, paramMap.get(key));
|
||||
}
|
||||
return post(urlString, formBuilder.build(), timeout);
|
||||
public static String post(String urlString, Map<String, String> formMap, int timeout) {
|
||||
return post(urlString, ofFormResponse(formMap), timeout);
|
||||
}
|
||||
|
||||
public static String post(String urlString, JSONObject body) {
|
||||
|
||||
Reference in New Issue
Block a user