JDK-6369510 : HttpURLConnection sets Content-Type to application/x-www-form-urlencoded
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-01-06
  • Updated: 2011-02-16
  • Resolved: 2006-02-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other JDK 6
5.0u10Resolved 6 b71Fixed
Description
FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP Professional Version 2002 Service Pack 2
Linux jclinux 2.4.21-32.0.1.EL #1 Tue May 17 18:01:37 EDT 2005 i686 i686 i386 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
In Java 5.0, HttpURLConnection, by defaults, sets Content-Type to application/x-www-form-urlencoded

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run code like this on JDK1.4.X and on JDK1.5 and see the value of the content-type header:

        URL url = new URL(argv[0]);

        HttpURLConnection connect = (HttpURLConnection) url.openConnection();
        connect.setRequestMethod("GET");
        connect.setDoInput(true);
        connect.setDoOutput(false);
        InputStream in;
        in = connect.getInputStream();

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting no content-type header
ACTUAL -
The request had a content-type header set to application/x-www-form-urlencoded

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION Content-Type is being set to application/x-www-form-urlencoded for all HttpURLConnections requests other than PUT requests. This is not necessary and could even cause problems for some servers. We do not need to set this content-type for GET requests. *** (#1 of 1): [ UNSAVED ] ###@###.###
2006-01-23