wangwei 6 anni fa
parent
commit
ce6bb564df

+ 10 - 11
src/main/java/cn/com/qmth/examcloud/web/cloud/CloudClientSupport.java

@@ -9,6 +9,7 @@ import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
@@ -42,14 +43,13 @@ public abstract class CloudClientSupport {
 	/**
 	 * 接口日志
 	 */
-	protected static final ExamCloudLog INTERFACE_LOG = ExamCloudLogFactory
-			.getLog("INTERFACE_LOGGER");
+	protected static final ExamCloudLog INTERFACE_LOG = ExamCloudLogFactory.getLog("INTERFACE_LOGGER");
 
 	private RestTemplate restTemplate;
 
 	private LogProperties logProperties;
 
-	private static String[] excludeFields = new String[]{"password", ".*Password"};
+	private static String[] excludeFields = new String[] { "password", ".*Password" };
 
 	private LogProperties getLogProperties() {
 		if (null == logProperties) {
@@ -169,8 +169,8 @@ public abstract class CloudClientSupport {
 		httpHeaders.add("App-Id", String.valueOf(AppSelfHolder.get().getAppId()));
 		httpHeaders.add("App-Code", String.valueOf(AppSelfHolder.get().getAppCode()));
 
-		String joinStr = StringUtil.join(AppSelfHolder.get().getAppId(),
-				AppSelfHolder.get().getAppCode(), startTime, AppSelfHolder.get().getSecretKey());
+		String joinStr = StringUtil.join(AppSelfHolder.get().getAppId(), AppSelfHolder.get().getAppCode(), startTime,
+				AppSelfHolder.get().getSecretKey());
 		byte[] bytes = SHA256.encode(joinStr);
 		String accessToken = ByteUtil.toHexAscii(bytes);
 		httpHeaders.add("Access-Token", accessToken);
@@ -193,8 +193,7 @@ public abstract class CloudClientSupport {
 
 		T respBody = null;
 		try {
-			ResponseEntity<String> respEntity = getRestTemplate().exchange(url, method,
-					requestEntity, String.class);
+			ResponseEntity<String> respEntity = getRestTemplate().exchange(url, method, requestEntity, String.class);
 			respBody = getRespBody(respEntity, responseType);
 
 			if (INTERFACE_LOG.isDebugEnabled() && getLogProperties().isNormalResponseLogEnable()) {
@@ -232,8 +231,7 @@ public abstract class CloudClientSupport {
 	 * @param responseType
 	 * @return
 	 */
-	protected <T> T post(String appName, String requestMapping, BaseRequest body,
-			Class<T> responseType) {
+	protected <T> T post(String appName, String requestMapping, BaseRequest body, Class<T> responseType) {
 		String url = buildUrl(appName, requestMapping);
 		return exchange(url, HttpMethod.POST, body, responseType);
 	}
@@ -270,12 +268,13 @@ public abstract class CloudClientSupport {
 	 * @return
 	 * @throws Exception
 	 */
-	public <T> T postForm(String appName, String requestMapping, FormRequest req,
-			Class<T> responseType) {
+	public <T> T postForm(String appName, String requestMapping, FormRequest req, Class<T> responseType) {
 		String url = buildUrl(appName, requestMapping);
 
 		MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
 		HttpHeaders httpHeaders = new HttpHeaders();
+		MediaType type = MediaType.parseMediaType("multipart/form-data");
+		httpHeaders.setContentType(type);
 
 		List<FormFilePart> formFilePartList = req.getFormFilePartList();
 		for (FormFilePart part : formFilePartList) {