1
votes

We are using the Web API REST endpoints of Microsoft CRM Dynamics online.

We try to create a new entry using a POST to the following URL https://OUR-ORG.crm4.dynamics.com/api/data/v9.0/customentities

We get success when the data contains normal characters, but as soon as a text property contains special characters like this

één

The request fails.

So sending

een 

is successful.

We are setting the "Content-Type" header to "application/json; charset=UTF-8"

---- programming language --- When we are using JAVA it fails.

URL crmURL = new URL(fullOdataURL);
HttpsURLConnection con = (HttpsURLConnection) crmURL.openConnection();

con.setRequestMethod("POST");

con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Authorization", "Bearer " + accesstoken);
con.setRequestProperty("OData-MaxVersion", "4.0");
con.setRequestProperty("OData-Version", "4.0");

con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(baaslogentryJSON.toString());
wr.flush();
wr.close();

When we use Postman to replay the request, the request is accepted.

So this becomes a JAVA question.

1
There are no special characters in Unicode. .NET and Windows use Unicode internally, so there's no question about whether they can handle UTF8. Please post your code, the query you used, the actual errors. You haven't provided any relevant information, not even the language you usedPanagiotis Kanavos
Setting the content type to application/json; charset=UTF-8 won't help if your code sends the data encoded as ASCII and mangles non-ANSI characters. Use Fiddler or another debugging proxy to check what's actually being sent to the HTTP service. I suspect you'll see that the request body is already mangledPanagiotis Kanavos

1 Answers

1
votes

Thanks to @pangiotis kanavos, I had a closer look at the java code. Of course as it turns out, the JAVA question already has an answer here: Java UTF-8 encoding not working HttpURLConnection

The code below is working for me (it kept the commented line here, to show the difference with the code in the question)

con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8"));
writer.write(baaslogentryJSON.toString());
writer.close();
//wr.writeBytes(baaslogentryJSON.toString());
wr.flush();
wr.close();