URL类发起http请求

    public static void doPost(String path){
        InputStream in = null;
        try {
            URL url=new URL(path);
            in = url.openConnection().getInputStream();
            String content= org.apache.commons.io.IOUtils.toString(in);
            System.out.println("content is " + content);
        } catch (IOException e) {
            System.err.println("error !");
            e.printStackTrace();
        }
    }

猜你喜欢

转载自ihenu.iteye.com/blog/2372498