Skip to content

Instantly share code, notes, and snippets.

@aogilvie
Last active December 17, 2015 14:29
Show Gist options
  • Save aogilvie/5625088 to your computer and use it in GitHub Desktop.
Save aogilvie/5625088 to your computer and use it in GitHub Desktop.
HttpUriRequest and HttpPut, sending a payload String with multilingual characters.

A Java String doesn't have an encoding but it can easily be forced into UTF-16 on conversions. ALWAYS specify UTF-8 when creating a new StringEntity from String!

Add payload to HttpPut
HttpPut hp = (HttpPut) this.request;
hp.setEntity(new StringEntity(yourStringPayload, "UTF-8"));
hp.setHeader("Content-Type", "application/json");
// ... then execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment