|
@@ -1,12 +1,17 @@
|
|
|
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;
|
|
@@ -19,6 +24,8 @@ import javax.net.ssl.X509TrustManager;
|
|
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+
|
|
|
public class HttpUtil {
|
|
|
|
|
|
// private static Logger log = LoggerFactory.getLogger(HttpUtil.class);
|
|
@@ -139,6 +146,9 @@ public class HttpUtil {
|
|
|
}
|
|
|
|
|
|
result = getResult(conn);
|
|
|
+ JSONObject message = JSONObject.fromObject(result);
|
|
|
+ message.accumulate("code", "");
|
|
|
+ result = message.toString();
|
|
|
} catch (Exception e) {
|
|
|
// 操作失败
|
|
|
// log.error("Http connection error!", e);
|
|
@@ -220,16 +230,27 @@ public class HttpUtil {
|
|
|
return text.toString();
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
JSONObject json = new JSONObject();
|
|
|
- json.accumulate("examId", 5);
|
|
|
+ json.accumulate("examId", 240);
|
|
|
+ json.accumulate("subjectCode", "CJFX17");
|
|
|
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";
|
|
|
- HttpUtil subjectHttp = new HttpUtil(dev, "123456", "11", "0");
|
|
|
+ // 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);
|
|
|
-
|
|
|
- // json.accumulate("subjectCode", "ldyCos001");
|
|
|
+ // ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
+ // IOUtils.copy(new
|
|
|
+ // ByteArrayInputStream(subjectJson.getBytes(StandardCharsets.UTF_8)),
|
|
|
+ // buffer);
|
|
|
+ // byte[] data = buffer.toByteArray();
|
|
|
+ // File target = new File("/Users/ting.yin/Desktop/test123.json");
|
|
|
+ // target.getParentFile().mkdirs();
|
|
|
+ // FileOutputStream ous = new FileOutputStream(target);
|
|
|
+ // ous.write(data);
|
|
|
+ // IOUtils.closeQuietly(ous);
|
|
|
// HttpUtil subjectHttp = new HttpUtil(
|
|
|
// "http://iepcc-ps.ecs.qmth.com.cn:80/api/exchange/outer/question/getSubjectivePaperStruct",
|
|
|
// "Fu234234CK!fsd9f0", "EPCC", "16923");
|
|
@@ -237,19 +258,17 @@ public class HttpUtil {
|
|
|
// System.out.println(subjectJson);
|
|
|
|
|
|
// HttpUtil paperHttp = new
|
|
|
- // HttpUtil("http://192.168.10.39:8007/api/exchange/outer/question/getSubjectivePaper",
|
|
|
- // "123456", "11", "0");
|
|
|
+ // HttpUtil();
|
|
|
// String paper = paperHttp.httpAction(null, json.toString());
|
|
|
// System.out.println(paper);
|
|
|
|
|
|
- // long start = System.currentTimeMillis();
|
|
|
// 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());
|
|
|
- // long end = System.currentTimeMillis();
|
|
|
- // System.out.println(end - start + ":" + studentJson);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ System.out.println(end - start);
|
|
|
}
|
|
|
}
|