Reputation: 161
I am trying to call an api. Whenever i include 'é' in the request body getting 400 bad request. When i remvove 'é' everything works fine. below is my code and response.
CloseableHttpClient httpClient = (CloseableHttpClient) getHttpClient();
HttpPost httpPost = getHttpPost("xxx");
StringEntity entity = new StringEntity(request.toString());
entity.setChunked(false);
httpPost.addHeader("content-type", "application/json");
httpPost.setEntity(entity);
System.out.println("contentlength = "+String.valueOf(entity.getContentLength()));
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(httpPost);
System.out.println("response = "
+ response);
StatusLine statusLine = response.getStatusLine();
System.out.println("statusLine = "
+ statusLine);
String responseEntity = EntityUtils.toString(response.getEntity());
System.out.println("responseEntity = "
+ responseEntity);
Response :
contentlength = 964 response = HttpResponseProxy{HTTP/1.1 400 Bad Request [Content-Length: 0,Chunked: false]} statusLine = HTTP/1.1 400 Bad Request responseEntity =
Upvotes: 1
Views: 5321
Reputation: 161
StringEntity entity = new StringEntity(request.toString(),"UTF-8");
this solved the issue.
Upvotes: 2
Reputation: 170
Set the content-type to:
"application/json;charset=UTF-8"
when sending the post request in the application you are using.
Upvotes: 1