zoukankan      html  css  js  c++  java
  • JAVA调用Rest服务接口

    package com.zouhao.dfx.web.controller;
    
    /**
     * Created by zouhao on 16/1/11.
     *
     * @ClassName: ${ClassName}
     * @Description: TODO
     * @author: zouhao
     * @date: 16/1/11
     */
    
    
    import java.io.*;
    
    import java.net.*;
    
    public class RestUtil {
    
        public String load(String url,String query) throws Exception
        {
    
        URL restURL = new URL(url);
    
            HttpURLConnection conn = (HttpURLConnection) restURL.openConnection();
    
            conn.setRequestMethod("POST");
    
            conn.setDoOutput(true);
    
            conn.setAllowUserInteraction(false);
    
            PrintStream ps = new PrintStream(conn.getOutputStream());
            ps.print(query);
    
            ps.close();
    
            BufferedReader bReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    
            String line,resultStr="";
    
            while(null != (line=bReader.readLine()))
    
            {
    
            resultStr +=line;
    
            }
    
            bReader.close();
    
            return resultStr;
    
        }
    
        public static void main(String []args) {
    
            try {
    
                RestUtil restUtil = new RestUtil();
    
                String resultString = restUtil.load("http://58.33.45.112:port/TrafficflowCommon/Handler.ashx","param1=d¶m2=e");
    
                } catch (Exception e) {
    
                // TODO: handle exception
    
                System.out.print(e.getMessage());
    
                }
    
            }
    
        }
  • 相关阅读:
    网络状态码含义——(比如204,304, 404, 504,502)
    Vue两个简易代替vuex的方法(eventBus,observable)
    单页面首屏加载慢解决方案
    前端监控和前端埋点
    ES5 和 ES6的继承
    mysql 隔离级别
    mysql 事务
    Seata
    Sentinel Dashboard 部署
    java 垃圾回器
  • 原文地址:https://www.cnblogs.com/zouhao510/p/5122813.html
Copyright © 2011-2022 走看看