Java的HttpURLConnection不支持REPORT / PROPFIND – 我该怎么办?

HttpURLConnection只支持GET,POST和HEAD之类的东西 – 但没有REPORT / PROPFIND.我将实现一个CalDAV-Client,但没有theese操作(如果我想使用它们,我得到一个ProtocolException)我必须使用auth编写/交付一个完整且庞大的HTTP库,依此类推.

“矫枉过正”.

如何使用PROPFIND和REPORT发送请求?

解决方法

我在WebDav上遇到类似PROPFIND方法的问题.

通过实施此解决方解决了问题:
https://java.net/jira/browse/JERSEY-639

try {
            httpURLConnection.setRequestMethod(method);
        } catch (final ProtocolException pe) {
            try {
                final Class<?> httpURLConnectionClass = httpURLConnection
                        .getClass();
                final Class<?> parentClass = httpURLConnectionClass
                        .getSuperclass();
                final Field methodField;
                // If the implementation class is an HTTPS URL Connection,we
                // need to go up one level higher in the heirarchy to modify the
                // 'method' field.
                if (parentClass == HttpsURLConnection.class) {
                    methodField = parentClass.getSuperclass().getDeclaredField(
                            "method");
                } else {
                    methodField = parentClass.getDeclaredField("method");
                }
                methodField.setAccessible(true);
                methodField.set(httpURLConnection,method);
            } catch (final Exception e) {
                throw new RuntimeException(e);

            }
     }

相关文章

应用场景 C端用户提交工单、工单创建完成之后、会发布一条工...
线程类,设置有一个公共资源 package cn.org.chris.concurre...
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量