|
@@ -1,6 +1,9 @@
|
|
|
package com.zskk.control;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -31,7 +34,13 @@ public class ViewController extends Controller {
|
|
|
this.renderJson(d);
|
|
|
}
|
|
|
|
|
|
- private static void doPost(String url, Map<String, String> map) throws IOException {
|
|
|
+ /**
|
|
|
+ * post请求
|
|
|
+ * @param url-请求地址
|
|
|
+ * @param map-参数集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String doPost(String url, Map<String, String> map) {
|
|
|
FormBody.Builder builder = new FormBody.Builder();
|
|
|
for (String key : map.keySet()) {
|
|
|
builder.add(key, map.get(key));
|
|
@@ -40,20 +49,44 @@ public class ViewController extends Controller {
|
|
|
RequestBody formBody = builder.build();
|
|
|
|
|
|
Request request = new Request.Builder().url(url).post(formBody).build();
|
|
|
-
|
|
|
+
|
|
|
try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
- if (!response.isSuccessful())
|
|
|
- throw new IOException("Unexpected code " + response);
|
|
|
- System.out.println(response.body().string());
|
|
|
-// return response.body().string();
|
|
|
-
|
|
|
+ if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
+ String content = response.body().string();
|
|
|
+ return content;
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期字符串格式转换
|
|
|
+ * @param dateStr
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Date parseStringToDate(String dateStr) {
|
|
|
+ if (dateStr == null) {
|
|
|
+ return new Date();
|
|
|
}
|
|
|
+ SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = null;
|
|
|
+ try {
|
|
|
+ date = sdf.parse(dateStr);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return date;
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
+ public static void main(String[] args) {
|
|
|
Map<String,String> paramsMap=new HashMap<String,String>();
|
|
|
paramsMap.put("institution_id", "44100001");
|
|
|
|
|
|
- doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
|
|
|
+ String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
|
|
|
+ System.out.println(contentString);
|
|
|
+
|
|
|
}
|
|
|
}
|