Java’s httpurlconnection does not support report / propfind – what should I do?

Httpurlconnection only supports things like get, post and head - but there is no report / propfind I will implement a caldav client, but there is no ese operation (if I want to use them, I get a protocolexception). I must write / deliver a complete and huge HTTP library using auth, and so on

"Overcorrection"

How do I send requests using propfind and report?

Solution

I encountered a problem similar to the propfind method on WebDAV

By implementing this solution, the problem is solved: 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);

            }
     }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>