Java的HttpURLConnection不支持REPORT / PROPFIND – 我该怎么办
发布时间:2020-12-14 05:54:56 所属栏目:Java 来源:网络整理
导读:HttpURLConnection只支持GET,POST和HEAD之类的东西 – 但没有REPORT / PROPFIND.我将实现一个CalDAV-Client,但没有theese操作(如果我想使用它们,我得到一个ProtocolException)我必须使用auth编写/交付一个完整且庞大的HTTP库,依此类推. “矫枉过正”. 如何使
HttpURLConnection只支持GET,POST和HEAD之类的东西 – 但没有REPORT / PROPFIND.我将实现一个CalDAV-Client,但没有theese操作(如果我想使用它们,我得到一个ProtocolException)我必须使用auth编写/交付一个完整且庞大的HTTP库,依此类推.
“矫枉过正”. 如何使用PROPFIND和REPORT发送请求? 解决方法
我在WebDav上遇到类似PROPFIND方法的问题.
通过实施此解决方案解决了问题: 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); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
热点阅读