Test.java
2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//package com.bsth;
//
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.util.HashMap;
//import java.util.Map;
//
//import org.apache.commons.io.IOUtils;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//
//public class Test {
//
// public static void main(String[] args) {
// Map<String, Object> map = new HashMap<>();
// map.put("timestamp", 1469764939000L);
// map.put("operCode", 128);
// map.put("deviceId", "66ML0007");
//
// Map<String , Object> dataMap = new HashMap<>();
// dataMap.put("requestCode", 161);
// dataMap.put("lineId", 1025);
// dataMap.put("operCode2", 38);
//
// map.put("data", dataMap);
// request(map, "http://192.168.168.171:9088/control/upstream");
//
// }
//
// private static Map<String, Object> request(Map<String, Object> map, String url) {
// InputStream in = null;
// OutputStream out = null;
// HttpURLConnection con = null;
// try {
// con = (HttpURLConnection)new URL(url).openConnection();
// con.setRequestMethod("POST");
// con.setRequestProperty("keep-alive", "true");
// con.setRequestProperty("accept", "*/*");
// con.setDoInput(true);
// con.setDoOutput(true);
// con.setReadTimeout(2500);
// con.setConnectTimeout(2500);
// out = con.getOutputStream();
// out.write("json=".getBytes());
// out.write(new ObjectMapper().writeValueAsBytes(map));
// out.flush();
// System.out.println("con.getResponseCode(): " + con.getResponseCode());
// if (con.getResponseCode() == 200) {
// in = con.getInputStream();
// ByteArrayOutputStream bout = new ByteArrayOutputStream();
// IOUtils.copy(in, bout); bout.close();
// System.out.println("Message:" + new String(bout.toByteArray()));
// return new ObjectMapper().readValue(bout.toByteArray(), Map.class);
// }
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// con.disconnect();
// try {
// if (in != null) in.close();
// if (out != null) out.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// return null;
// }
//}