Skip to main content

Posts

Showing posts from December, 2022

HTTP 400 Bad Request - Apache HTTP Client - HTTP POST JSON Message

  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  HTTP /1.1 400 Bad Request ...    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. But, we were still buzzed with the problem why HTTPClient is not working. We tried using a proxy to capture HTTP Header and Body. So, as to compare difference between various user agents.  And, we identified that Content-Length  for User-Agent : Apache-HttpClient/4.5