首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

java post xml源

2013-11-02 
java post xml流代码如下:?public String sendPostXml(String url, String postXml) {StringBuffer sb n

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();}

?

?

?

热点排行