zoukankan      html  css  js  c++  java
  • JAVA发送xml格式的接口请求

     /**
         * 
         * @param urlStr  接口地址
         * @param xmlInfo   xml格式参数数据
         * @return
         */
        public static String sendMsgXml(String urlStr, String xmlInfo) {
            StringBuffer buffer = new StringBuffer();
            try {
                URL url = new URL(urlStr);
                URLConnection con = url.openConnection();
                con.setDoOutput(true);
                OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(), "utf-8");
                System.out.println("Exedata start
    " + xmlInfo + "
    Exe end");
                out.write(xmlInfo);
                //out.write(new String(request.getBytes("ISO-8859-1")));
                out.flush();
                out.close();
                BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
                String line = "";
                for (line = br.readLine(); line != null; line = br.readLine()) {
                    buffer.append(line);
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return buffer+"";
        }
    

      

  • 相关阅读:
    [LeetCode] Wiggle Sort
    [LeetCode] Perfect Squares
    [LeetCode] Minimum Window Substring
    [LeetCode] Valid Sudoku
    [LeetCode] Sudoku Solver
    [LeetCode] First Bad Version
    [LeetCode] Find the Celebrity
    [LeetCode] Paint Fence
    [LeetCode] H-Index II
    [LeetCode] H-Index
  • 原文地址:https://www.cnblogs.com/pxblog/p/11436595.html
Copyright © 2011-2022 走看看