java请求url返回json

    

 1 package cn.it.test;
 2 
 3 import java.io.BufferedReader;
 4 import java.io.IOException;
 5 import java.io.InputStreamReader;
 6 import java.net.MalformedURLException;
 7 import java.net.URL;
 8 import java.net.URLConnection;
 9 
10 public class Demo02 {
11 
12     /**
13      * @param args
14      */
15     public static void main(String[] args) {
16         String url = "http://10.19.92.132:8080/wssp/formlistenerservlet?fid=2b95e5b8:13b96f5bdff:-7fff&forminstid=e0827606155a41e29a6470f142e626f3&procinst_id=55550899:157d0434850:-7fd8&urlAppuid=1c9263c0671e48eaa8ea2bc121e9c5a2";
17         String json = loadJSON(url);
18         System.out.println(json);
19     }
20 
21     public static String loadJSON(String url) {
22         StringBuilder json = new StringBuilder();
23         try {
24             URL oracle = new URL(url);
25             URLConnection yc = oracle.openConnection();
26             BufferedReader in = new BufferedReader(new InputStreamReader(
27                     yc.getInputStream(),"utf-8"));//防止乱码
28             String inputLine = null;
29             while ((inputLine = in.readLine()) != null) {
30                 json.append(inputLine);
31             }
32             in.close();
33         } catch (MalformedURLException e) {
34         } catch (IOException e) {
35         }
36         return json.toString();
37     }
38 }

 

转载于:https://www.cnblogs.com/may12138/p/6211237.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值