United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6369510 : HttpURLConnection sets Content-Type to application/x-www-form-urlencoded

Details
Type:
Bug
Submit Date:
2006-01-06
Status:
Resolved
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2006-02-04
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.net
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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



Hardware and Software, Engineered to Work Together