Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: HTTPBuilder-0.5.1
-
Fix Version/s: HTTPBuilder-0.5.2
-
Component/s: HttpBuilder
-
Labels:None
-
Number of attachments :
Description
Whether i pass the content-type to the request method, e.g.
http.request(Method.POST, "text/xml") { req ->
or set it explicitely with
requestContentType = "text/xml"
the POSTed http request will always have content-type "application/xml".
The problem lies in HTTPBuilder.doRequest( final RequestConfigDelegate delegate ): it does not set the request content-type at all (it only sets the accept-content-type). I guess the underlying HttpClient library uses "application/xml" as default when no content type is set.
There is a simple work around: set the content-type header explicitely, as in
headers = [ 'Content-Type': 'text/xml']
You're sort of right. The EncoderRegistry class is setting the content-type header. However for content-types that have multiple variants (See ContentType.java,) each encoder function is taking the 'default' representation for that content-type, and not taking into consideration if a more specific content-type string was given.
For example, if you did something like this:
http.request(POST,'text/plain') { body = "blah" response.success = { resp -> System.out << resp.data } }you'd see:
That said, it definitely should respect the string content-type you've given. I'll fix this for 0.5.2.