[
https://issues.apache.org/jira/browse/HTTPCLIENT-2253?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oleg Kalnichevski resolved HTTPCLIENT-2253.
-------------------------------------------
Resolution: Invalid
> HTTP 400 Bad Request - Apache HTTP Client - HTTP POST JSON Message
> ------------------------------------------------------------------
>
> Key: HTTPCLIENT-2253
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2253
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Reporter: dinesh sachdev
> Priority: Major
>
> For one of our projects, we faced issue where-in -
> * We were utilizing Apache HTTP Client 4.5 and doing HTTP Post of JSON
> Message.
> * This was resulting HTTP Response as
> * {color:#ff0000}HTTP /1.1 400 Bad Request ... {color}
> On analysis, we found that HTTP Post was failing just for Big JSON Files of
> size greater then 7 MB. So, initially we thought it to be a server side
> issue.
>
> But after further analysis we found that Unix CURL command was able to
> successfully POST message to API. Thus, we came to know that something was
> wrong with Scala (JAVA) client code that was using HTTP Client.
>
> Solution -
>
> * We further updated the code and used _java.net.\{HttpURLConnection, URL}_
> instead of _org.apache.http.client.methods.\{HttpPost}_ and it worked fine
> for us.
>
> Even though, we specified below in code snippet -
> val post = new HTTPPost("url")
> post.setHeader("content-type", "application/json")
> post.setEntity( new StringEntity("json"))
> ....
> ....
> client.execute(post)
> ...
>
> HTTP Header contains _Content-type:application/json._ But, StringEntity
> encodes sequence of bytes with default encoding (ISO 8859-1) instead of
> ContentType.APPLICATION_JSON, unless it is explicitly specified like below -
> * _new_ _StringEntity(string, ContentType.APPLICATION_JSON)_
>
> Either this should fail with specific message like - Content Type is
> different in header and StringEntity, instead of HTTP 400 Bad Request,
> Or ContentType set in header should be given priority and StringEntity should
> be encoded accordingly.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]