java后台访问网址url

阅读 42

2021-09-24

public static JSONObject doGetJson(String url) throws ClientProtocolException, IOException {
              JSONObject jsonObject =null;
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet =new HttpGet(url);
            HttpResponse response =  client.execute(httpGet);
            HttpEntity entity =response.getEntity();
            if(entity!=null)
            {
          
                String result =EntityUtils.toString(entity, "UTF-8"); 
                jsonObject =JSON.parseObject(result); 
            }
            
            return jsonObject;
        }

精彩评论(0)

0 0 举报