HttpURLConnection仅支持GET,POST和HEAD之类的功能,但不支持REPORT / PROPFIND。我将实现CalDAV-Client,但没有这些操作(如果要使用它们,我会收到ProtocolException),我必须使用auth等方式编写/交付一个完整且庞大的HTTP库。
“过度杀伤力”。
如何使用PROPFIND和REPORT发送请求?
最佳答案
对于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);
}
}