java post xml流
代码如下:
?
public String sendPostXml(String url, String postXml) {StringBuffer sb = new StringBuffer();BufferedReader reader = null;OutputStreamWriter out = null;try {HttpURLConnection con = HttpRequestUtils.getUrlConnection(url, postXml.length());con.setRequestProperty("Pragma:", "no-cache"); con.setRequestProperty("Cache-Control", "no-cache"); con.setRequestProperty("Content-Type", "text/xml"); out = new OutputStreamWriter(con .getOutputStream()); out.write(new String(postXml.getBytes("UTF-8"))); out.flush(); out.close(); //获取post端的响应的数据 reader = new BufferedReader(new InputStreamReader(con .getInputStream())); String lines; while ((lines = reader.readLine()) != null) { lines = new String(lines.getBytes(), "UTF-8"); sb.append(lines); } reader.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{if (out != null){try {out.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if (reader != null){try {reader.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}return sb.toString();}?
?
?