瀏覽代碼

add utf8 to header

梅杰 6 年之前
父節點
當前提交
392aef4881
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/main/java/com/mooctest/service/FinalReportService.java

+ 5 - 1
src/main/java/com/mooctest/service/FinalReportService.java

@@ -13,9 +13,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.StringHttpMessageConverter;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
+import java.nio.charset.Charset;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -78,11 +81,12 @@ public class FinalReportService {
         List<FinalReport> finalReports = finalReportDao.findByExamIdAndCaseId(task.getExamId(), task.getCaseId());
 
         HttpHeaders headers = new HttpHeaders();
-        headers.set("Content-Type", "application/json");
+        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
 
         JSONObject reportJson = genJsonForExport(task, finalReports);
         HttpEntity<String> request = new HttpEntity<>(reportJson.toJSONString(), headers);
         RestTemplate rt = HttpUtil.getRestTemplate();
+
         String url = rt.postForObject(reportExportAddr, request, String.class);
         return url;
     }