Browse Source

首页获取最近打卡信息修改

anderx 1 year ago
parent
commit
d867e62e73
1 changed files with 7 additions and 9 deletions
  1. 7 9
      src/main/java/com/goafanti/common/utils/HttpUtils.java

+ 7 - 9
src/main/java/com/goafanti/common/utils/HttpUtils.java

@@ -14,7 +14,7 @@ import org.apache.http.util.EntityUtils;
 
 import java.io.IOException;
 import java.net.UnknownHostException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -53,7 +53,6 @@ public class HttpUtils {
 		  * @param url 地址
 		  * @param map 参数
 		  * @param type  0 json  1body
-		  * @return
 		  */
 		public static JSONObject httpPost(String url,Map<String, Object>map,Integer type) {
 			HttpClient httpClient = HttpClientBuilder.create().build();
@@ -61,10 +60,10 @@ public class HttpUtils {
 			httpPost.setHeader("Accept", "application/json");
 			if (type==0){
 				httpPost.addHeader("Content-type", "application/json");
-				httpPost.setEntity(new StringEntity(JSON.toJSONString(map), Charset.forName("UTF-8")));
+				httpPost.setEntity(new StringEntity(JSON.toJSONString(map), StandardCharsets.UTF_8));
 			}else{
 				httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
-				httpPost.setEntity(new StringEntity(ParamMap(map), Charset.forName("UTF-8")));
+				httpPost.setEntity(new StringEntity(ParamMap(map), StandardCharsets.UTF_8));
 			}
 
 			HttpResponse response = null;
@@ -92,13 +91,12 @@ public class HttpUtils {
 			}
 
 	private static String ParamMap(Map<String, Object> map) {
-		StringBuffer str =new StringBuffer();
+		StringBuilder str =new StringBuilder();
 		Set<String> strings = map.keySet();
 		for (String string : strings) {
-			str=str.append(string).append("=").append(map.get(string)).append("&");
-		}
-		String substring = str.substring(0, str.length() - 1);
-		return substring;
+            str.append(string).append("=").append(map.get(string)).append("&");
+        }
+        return str.substring(0, str.length() - 1);
 	}
 
 	public static void main(String[] args) {