RESTClient使用HTTP Get Request

时间:2013-06-17 16:19:38

标签: java json rest restful-url

我正在尝试编写一个使用HTTP GET方法的JSON客户端,我得到500的响应。我试过的代码如下,是否有相同的错误?我试图设置的请求参数是entityName = Nila,parentEntity = 500000001作为参数。

URL url = new URL("http://192.168.210.74:9763/services/testEntityService?entityName=Nila&parentEntity=500000001");



        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
                (conn.getInputStream())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

        conn.disconnect();

    } catch (MalformedURLException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    }

}

1 个答案:

答案 0 :(得分:1)

内部服务器错误是问题出在服务器端。