RESTful API를 만들다가 만나는 메시지
HttpURLConnection: HTTP method DELETE doesn't support output
HTTP DELETE 메쏘드 사용 시, request body를 구성하면 위와 같은 에러가 떨어짐...
명시적으로 body를 구성해서는 안된다는 이야기는 없는데.. 에러가 떨어짐..
jdk8 에서 픽스가 되었다는데...
jdk 1.7.0_45 에서 jdk 1.8.0_20 으로 업그레이드 하고 해결됨.. 아우...
JDK-7157360 : HttpURLConnection: HTTP method DELETE doesn't support output |
Type: | Bug | Submit Date: | 2012-03-28 | Status: | Closed | Updated Date: | 2013-08-24 | Project Name: | JDK | Resolved Date: | 2013-06-22 | Component: | core-libs | OS: | generic | Sub-Component: | java.net | CPU: | generic | Priority: | P4 | Resolution: | Fixed | Affected Versions: | 6u31 | Fixed Versions: | |
|
|
When using HttpURLConnection, if I set the request method to "DELETE" and attempt to get to the output stream to write the entity body, I get:
Exception in thread "main" java.net.ProtocolException: HTTP method DELETE doesn't support output
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1004)
As it turns out, sun.net.www.protocol.http.HttpURLConnection explicitly denies access to the output stream if the request method is DELETE.
This restriction is likely a bug in the HttpURLConnection implementation, as RFC 2616 does not explicitly forbid or discourage request bodies in DELETE requests.
Note that Apache HTTP Client and all major browsers do allow request bodies in DELETE requests.
This problem is actually the root cause of the following JavaFX issue: http://javafx-jira.kenai.com/browse/RT-20664 (WebView is unable to include request entities in DELETE requests due to HttpURLConnection limitation)
Test program:
public class DeleteWitBodyTest {
public static void main(String[] args) throws IOException {
String url = "http://javafx-jira.kenai.com/rest/api/1.0/issues/47181/watchers";
HttpURLConnection c = (HttpURLConnection) new URL(url).openConnection();
c.setRequestMethod("DELETE");
c.setDoOutput(true);
OutputStream os = c.getOutputStream();
os.write("dummy".getBytes("UTF-8"));
os.close();
}
}
Expected output:
<None>
Actual output:
Exception in thread "main" java.net.ProtocolException: HTTP method DELETE doesn't support output
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1004)
at deletewitbodytest.DeleteWitBodyTest.main(DeleteWitBodyTest.java:14)
|
|
|
URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/fd050ba1cf72
User: chegar
Date: 2013-06-22 07:22:43 +0000
| | URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/fd050ba1cf72
User: lana
Date: 2013-07-05 18:35:47 +0000
| | Verified in b103 |
|