【问题标题】:RESTClient using HTTP Get RequestRESTClient 使用 HTTP 获取请求
【发布时间】:2013-06-17 16:19:37
【问题描述】:

我正在尝试编写一个使用 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();

    }

}

【问题讨论】:

  • 嗯,问题出在服务器端……
  • 首要任务 - 您要连接的服务是否接受应用程序/json?我建议问题出在服务器端,而不是客户端

标签: java json rest restful-url


【解决方案1】:

这是一个内部服务器错误,是的,问题出在服务器端。

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多