• 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 }
  • 相关阅读:
    SQL Server 2005高级程序设计
    SQL语言艺术
    无益的程序
    Django Ajax动态图形监控
    C/C++ Qt 基本文件读写方法
    Django 实现统计网站访问状态
    Python 实现 WebSocket 通信
    Django Admin后台定制简单监控页
    Django Ajax 实现Web命令行执行
    C/C++ Qt QThread 线程组件应用
  • 原文地址:https://www.cnblogs.com/may12138/p/6211237.html
Copyright © 2020-2023  润新知