6

HttpURLConnectionは、GET、POST、HEADなどのみをサポートしますが、REPORT/PROPFINDはサポートしません。CalDAV-Clientを実装しますが、これらの操作を使用しないと(ProtocolExceptionが発生します)、authなどを使用して完全で巨大なHTTPライブラリを作成/配信する必要があります。

「やり過ぎ」。

PROPFINDとREPORTを使用してリクエストを送信するにはどうすればよいですか?

4

8 に答える 8

4

PROPFIND メソッドの WebDav でも同様の問題がありました。

このソリューションを実装して問題を解決しました: 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);

            }
     }
于 2014-08-26T14:54:55.747 に答える
3

これについては、HTTPライブラリではなく、WebDAVライブラリを探すことをお勧めします。

たぶん、ApacheJackrabbitを見てください。

于 2010-08-11T14:56:42.010 に答える
2

Apache HTTPクライアントなどの別のHTTPライブラリを使用して、その拡張を試みることができますHttpRequestBase(たとえばを参照)HttpGetHttpPost

または、WebDAVクライアントライブラリを直接使用することもできます。

于 2010-08-11T15:00:11.743 に答える
0

Caldav4jの使用を検討してください

それはサポートします:

  • レポートリクエストの簡単な生成
  • httpclient3.0に基づく
  • アンドロイドアプリ
  • 現在、jackrabbitに移行しています
于 2011-02-28T23:02:48.590 に答える
0
private static void setRequestMethod(HttpURLConnection conn, String method) throws Throwable {
    try {
        conn.setRequestMethod(method);
    } catch (ProtocolException e) {
        Class<?> c = conn.getClass();
        Field methodField = null;
        Field delegateField = null;
        try {
            delegateField = c.getDeclaredField("delegate");
        } catch (NoSuchFieldException nsfe) {

        }
        while (c != null && methodField == null) {
            try {
                methodField = c.getDeclaredField("method");
            } catch (NoSuchFieldException nsfe) {

            }
            if (methodField == null) {
                c = c.getSuperclass();
            }
        }
        if (methodField != null) {
            methodField.setAccessible(true);
            methodField.set(conn, method);
        }

        if (delegateField != null) {
            delegateField.setAccessible(true);
            HttpURLConnection delegate = (HttpURLConnection) delegateField.get(conn);
            setRequestMethod(delegate, method);
        }
    }
}
于 2017-04-03T00:14:27.933 に答える