JAVA以POST方式提交XML获取返回值(返回格式为XML)
发布网友
发布时间:2023-08-07 15:32
我来回答
共1个回答
热心网友
时间:2023-09-14 16:13
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setRequestMethod(“POST”);
OutputStream outputStream = httpUrlConn.getOutputStream();
outputStream.write(xml);
outputStream.close();
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();追问请问能否再详细点呢 比如buffer.append(str); 的buffer是哪里来的
追答StringBuffer buffer = new StringBuffer();