RESTFul服务-PUT呼叫失败,出现http 411错误

时间:2018-10-16 18:59:10

标签: java rest put

我正在尝试使用输入法为“ PUT”的调用Rest服务。执行服务时,出现HTTP 411错误。 HTTP 411与内容长度有关,我什至尝试将内容长度设置为0,但仍然失败。请在下面找到相同的代码段,您能帮我解决此问题吗?

        URL url = new URL(
                "https://xxx/api/1.0/empPortalAcknowledgeAndUnassigned/updateCheckInStatus"
                        + inputParm);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("PUT");
        conn.setRequestProperty("Authorization", access_token);
        // conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Accept", "application/json");
        conn.setConnectTimeout(1000);
        conn.setReadTimeout(1000);
        conn.setRequestProperty("Content-Length", "0");
        conn.addRequestProperty("Content-Length", "0");
        if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }
        System.out.println("Output from Server ...." + "Response Code::" + conn.getResponseCode() + "\n");
        conn.disconnect();

1 个答案:

答案 0 :(得分:0)

您尝试通过java.text.SimpleDateFormat创建一个https连接。请改用HttpURLConnection。 (Http s UrlConnection)