REST调用:连接超时

时间:2015-04-12 13:19:11

标签: java rest jersey

我有一个REST网址 - http://testing.com/account/v1/person/21324

当我从浏览器调用时,我在浏览器中收到JSON响应。但是当我从Java调用(使用HttpURLConnection)调用它时,它会抛出异常“连接超时”。

请求之间有什么区别。

以下代码:

private static final String targetURL =
        "http://testing.com/account/v1/person/21324";
URL restServiceURL = new URL(targetURL);

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

if (httpConnection.getResponseCode() != 200) {
    throw new RuntimeException("HTTP GET Request Failed with Error code : "
            + httpConnection.getResponseCode());
}

0 个答案:

没有答案