Bug 41518 - JMeter changes the HTTP header Content Type for POST request
Summary: JMeter changes the HTTP header Content Type for POST request
Alias: None
Product: JMeter
Classification: Unclassified
Component: HTTP (show other bugs)
Version: Nightly (Please specify date)
Hardware: All Linux
: P2 major (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
Depends on:
Reported: 2007-02-01 11:37 UTC by Houqiang Yan
Modified: 2007-04-16 15:54 UTC (History)
0 users

Suggested patch (17.46 KB, patch)
2007-04-13 01:31 UTC, Alf Hogemark
Details | Diff
Updated suggested patch (28.28 KB, patch)
2007-04-16 03:36 UTC, Alf Hogemark
Details | Diff
Updated suggested patch (28.31 KB, patch)
2007-04-16 03:50 UTC, Alf Hogemark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Houqiang Yan 2007-02-01 11:37:40 UTC
I have an application which sends a POST request with Content-Type:
text/plain;.charset=utf-8. However, JMeter changes the Content-Type to
application/x-www-form-urlencoded and cause 500 error from server. This happen
during the recording and replaying. The header record in the script is
Content-Type: text/plain;.charset=utf-8 though.

The content in the HTTP POST body includes both binary and characters.

The build I am using is nightly build 20060921.
Comment 1 Alf Hogemark 2007-04-13 01:31:13 UTC
Created attachment 19945 [details]
Suggested patch

This patch allows the user to specify what "content-type" header should be sent
for a HTTP POST request, by adding a "HTTP Header Manager" config element as a
child of the sampler, and then setting the content-type header and value there.

If it is a multipart post request, then the code will set the content-type to
the correct multipart / boundary value, no matter what the user has specified.

If the user has not specified a content-type header via the "HTTP Header
Manager", then the code will set content-type

If the user specifies no parameters for the POST request, but specifies a
filename and mimetype, but no "file field name", then the file will be sent in
the post body, with the value specified in "mimetype" as the value of the
"content-type" header.

If the user specifies one or more parameters, but none of the parameters have a
name, then all the parameter values are concatenated, and sent as the sole post

This patch also contains minor changes to the HTTP Proxy Server, to allow the
proxy server to serve HTTP Post requests which has content-type different from 

"application/x-www-form-urlencoded", by just adding a parameter with value, but
no name, to the http sampler.
This, I think, should allow you to use the HTTP Proxy Server to record any HTTP
post. So I think this patch also solves bug 39641.
Comment 2 Sebb 2007-04-13 14:48:41 UTC
The HttpRequestHdr patch causes test failures - it changes the number of 
arguments that are parsed.
Comment 3 Alf Hogemark 2007-04-16 03:36:59 UTC
Created attachment 19970 [details]
Updated suggested patch

I have fixed the problem exposed by the failing JUnit test, HTTP GET request
incorrectly got an extra parameter, due to the parsing of the "request body".
I have also added some new junit tests, and expanded the existing junit tests.
Comment 4 Alf Hogemark 2007-04-16 03:50:46 UTC
Created attachment 19971 [details]
Updated suggested patch

One change compared to the last suggested patch : now only add parameter for
the whole post body, if the length of postbody is greater than 0.
Comment 5 Sebb 2007-04-16 15:54:04 UTC
Thanks for the fixes.

Patch 19971 applied to SVN as r529431