首页 > 技术文章 > HttpURLConnection

yqlwl66 2014-11-19 15:42 原文

public  static ProductView getProductDetail(String id) {
        String path ="http://192.168.7.45:8080/Service/ws/product/detail/"+id;
        URL url = null;   
        ProductView pv=null;
        try {    
            url = new URL(path);    
        } catch (Exception e) {    
            e.printStackTrace();    
         }    
        try {    
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();//利用HttpURLConnection对象,我们可以从网络中获取网页数据.    
            conn.setRequestMethod("GET");// 提交模式
            conn.setDoOutput(true);   
            conn.connect();
            ObjectMapper om=new ObjectMapper();
            pv=om.readValue(conn.getInputStream(), ProductView.class);
        } catch (IOException e) {    
            e.printStackTrace();  
        }
        return pv;
    }

推荐阅读