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);
}
}