本文介绍了Java的HttpURLConnection不支持REPORT / PROPFIND-我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpURLConnection仅支持GET,POST和HEAD之类的内容,但不支持REPORT / PROPFIND。我要实现一个CalDAV-Client,但是没有这些操作(如果要使用它们,我会收到ProtocolException),我必须使用auth等来编写/交付一个完整且庞大的HTTP库。

HttpURLConnection does only support things like GET, POST and HEAD - but no REPORT/PROPFIND. I'm going to implement a CalDAV-Client but without theese operations (if I want to use them I get a ProtocolException) I have to write/deliver a complete and huge HTTP library with auth and so on.

过度杀伤。

如何通过PROPFIND和REPORT发送请求?

How do I send requests with PROPFIND and REPORT?

推荐答案

对于PROPFIND方法,我在WebDav上也遇到了类似的问题。

I had similar problem on WebDav for PROPFIND method.

通过实现以下解决方案解决了该问题:

Solved the problem by implementing this solution: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);

            }
     }

这篇关于Java的HttpURLConnection不支持REPORT / PROPFIND-我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 07:12