|
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
|
public static final String SENDER = "002"; // 发送者
public static final String RECEIVER = "u8"; // 接收者
public static final String PROC_ADD = "add"; // 处理——添加
public static final String PROC_DEL = "delete"; // 处理——删除
public static final String PROC_EDIT = "edit"; // 处理——编辑
public static final String PROC_LIST = "query"; // 处理——查询所有
public static final String CODEEXCHANGED = "N"; // 导入的代码未进行转码
public static final String EXPORTNEEDEXCH = "N"; // 导出的代码不需要转码
public static final String VERSION = "1.0"; // 版本
public static String sendXML(String urlString, String xmlString) throws Exception {
// 发送xml
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(3000000);
con.setReadTimeout(3000000);
con.setDoInput(true);
con.setDoOutput(true);
con.setAllowUserInteraction(false);
con.setUseCaches(false);
con.setRequestMethod("POST");
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
// 发送Request消息
OutputStream out = con.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.write(xmlString.getBytes("utf-8"));
// 获取Response消息
InputStream in = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String s = null;
while ((s = br.readLine()) != null) {
sb.append(s);
}
String responseXml = sb.toString();
return responseXml;
}
}
|