String XMLString = "";
try {
HttpURLConnection httpConn;
httpConn = (HttpURLConnection) new URL(url)
.openConnection();
httpConn.setConnectTimeout(300000);
httpConn.setReadTimeout(300000);
httpConn.setDoOutput(true);
httpConn.setUseCaches(false);
httpConn.setRequestMethod("POST");
OutputStream out = httpConn.getOutputStream();
out.write(xmlStr.getBytes("UTF-8"));
out.flush();
out.close();
int responseCode = httpConn.getResponseCode();
if (HttpURLConnection.HTTP_OK == responseCode) {
StringBuilder sb = new StringBuilder();
String readLine;
BufferedReader responseReader = new BufferedReader(
new InputStreamReader(httpConn.getInputStream()));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
responseReader.close();
XMLString = sb.toString();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
if (logger.isDebugEnabled()) {
//打印xmlString报文
logger.debug("--------------返回报文:" + XMLString);
try {
HttpURLConnection httpConn;
httpConn = (HttpURLConnection) new URL(url)
.openConnection();
httpConn.setConnectTimeout(300000);
httpConn.setReadTimeout(300000);
httpConn.setDoOutput(true);
httpConn.setUseCaches(false);
httpConn.setRequestMethod("POST");
OutputStream out = httpConn.getOutputStream();
out.write(xmlStr.getBytes("UTF-8"));
out.flush();
out.close();
int responseCode = httpConn.getResponseCode();
if (HttpURLConnection.HTTP_OK == responseCode) {
StringBuilder sb = new StringBuilder();
String readLine;
BufferedReader responseReader = new BufferedReader(
new InputStreamReader(httpConn.getInputStream()));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
responseReader.close();
XMLString = sb.toString();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
if (logger.isDebugEnabled()) {
//打印xmlString报文
logger.debug("--------------返回报文:" + XMLString);
}
url:地址
xmlStr:发送报文
XMLString:返回报文