|
@@ -1,17 +1,12 @@
|
|
|
package cn.com.qmth.stmms.admin.utils;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.security.cert.CertificateException;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
import java.util.Map;
|
|
@@ -24,11 +19,12 @@ import javax.net.ssl.X509TrustManager;
|
|
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
public class HttpUtil {
|
|
|
|
|
|
- // private static Logger log = LoggerFactory.getLogger(HttpUtil.class);
|
|
|
+ private static Logger log = LoggerFactory.getLogger(HttpUtil.class);
|
|
|
|
|
|
/** 默认的编码格式 */
|
|
|
public static final String DEFAULT_CHARSET = "UTF-8";
|
|
@@ -151,13 +147,9 @@ public class HttpUtil {
|
|
|
result = message.toString();
|
|
|
} catch (Exception e) {
|
|
|
// 操作失败
|
|
|
- // log.error("Http connection error!", e);
|
|
|
+ log.error("Http connection error!", e);
|
|
|
e.printStackTrace();
|
|
|
- JSONObject message = JSONObject.fromObject(e.getMessage());
|
|
|
- if (ERROR_CODE.equals(message.getString("code"))) {
|
|
|
- return e.getMessage();
|
|
|
- }
|
|
|
- return null;
|
|
|
+ return e.getMessage();
|
|
|
} finally {
|
|
|
try {
|
|
|
if (os != null) {
|
|
@@ -169,7 +161,7 @@ public class HttpUtil {
|
|
|
is = null;
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
- // log.error("Http connection error!", e);
|
|
|
+ log.error("Http connection error!", e);
|
|
|
}
|
|
|
|
|
|
if (conn != null) {
|
|
@@ -233,14 +225,14 @@ public class HttpUtil {
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.accumulate("examId", 240);
|
|
|
- json.accumulate("subjectCode", "CJFX17");
|
|
|
+ json.accumulate("subjectCode", "CJFX18");
|
|
|
String test = "https://ecs-test.ea100.com.cn/api/exchange/outer/question/getSubjectivePaperStruct";
|
|
|
// String dev =
|
|
|
// "https://dev.ea100.com.cn/api/exchange/outer/question/getSubjectivePaperStruct";
|
|
|
long start = System.currentTimeMillis();
|
|
|
HttpUtil subjectHttp = new HttpUtil(test, "123456", "11", "17128");
|
|
|
String subjectJson = subjectHttp.httpAction(null, json.toString());
|
|
|
- System.out.println(subjectJson);
|
|
|
+ // System.out.println(subjectJson);
|
|
|
// ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
// IOUtils.copy(new
|
|
|
// ByteArrayInputStream(subjectJson.getBytes(StandardCharsets.UTF_8)),
|
|
@@ -262,12 +254,13 @@ public class HttpUtil {
|
|
|
// String paper = paperHttp.httpAction(null, json.toString());
|
|
|
// System.out.println(paper);
|
|
|
|
|
|
- // HttpUtil studentHttp = new HttpUtil(
|
|
|
- // "https://192.168.10.39:8007/api/exchange/outer/question/getSubjectiveQuestion",
|
|
|
- // "123456", "11", "0");
|
|
|
- // json.accumulate("startId", 0);
|
|
|
- // json.accumulate("size", 10);
|
|
|
- // String studentJson = studentHttp.httpAction(null, json.toString());
|
|
|
+ HttpUtil studentHttp = new HttpUtil(
|
|
|
+ "https://ecs-test.ea100.com.cn/api/exchange/outer/question/getSubjectiveQuestion", "123456", "11",
|
|
|
+ "17128");
|
|
|
+ json.accumulate("startId", 0);
|
|
|
+ json.accumulate("size", 1);
|
|
|
+ String studentJson = studentHttp.httpAction(null, json.toString());
|
|
|
+ System.out.println(studentJson);
|
|
|
long end = System.currentTimeMillis();
|
|
|
System.out.println(end - start);
|
|
|
}
|