I got an interesting thing.
Note the 'Â' signs, they come from when i make a clone of a project description.
I do not modify the text, this just appears from blank spaces.
This is what i send in;
<td> </td>
<td> </td>
<td> </td>
From C# i use the following code;
RestRequest request = new RestRequest("?resultFormat=xml&resultInclude=[Id,Name]", Method.POST);
request.Method = Method.POST;
request.Parameters.Clear();
request.AddHeader("Accept", "*/*");
request.AddHeader("Content-Type", "application/xml");
request.AddParameter("application/xml", payLoad, ParameterType.RequestBody);
I have tried both swedish and american UTF-8 coding in server locale, same phenomena.
Best Regards
Björn Zachrisson
using System;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Linq;
using RestSharp;
namespace TargetProcess.Rest.Sample
{
class Program
{
private static Task<IRestResponse> CreateProject(string name, string description)
{
// Ensure TLS 1.2 enabled (https://www.targetprocess.com/blog/2016/03/targetprocess-will-start-enforcing-tls-1-2-encryption/).
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
// Using RestSharp v. 105.2.3. Set your TargetProcess projects API URL here.
var client = new RestClient("https://md5.tpondemand.com/api/v1/Projects");
var request = new RestRequest("?access_token={access_token}&resultFormat=xml&resultInclude=[Id,Name,Description]", Method.POST);
// Set your TargetProcess API access token here (https://www.targetprocess.com/guide/faq/rest-api-authentication/).
request.AddUrlSegment("access_token", "MY_TARGETPROCESS_ACCESS_TOKEN");
// Accept xml in utf8.
request.AddHeader("Accept", "application/xml; charset=utf-8");
var project = new XElement("Project",
new XAttribute("Name", name),
new XAttribute("Description", description));
request.Parameters.Clear();
// Send xml in utf8.
request.AddParameter("application/xml; charset=utf-8", project.ToString(), ParameterType.RequestBody);
return client.ExecutePostTaskAsync(request);
}
static void Main()
{
const string description = "<table>" +
"<tr><th>ID</th><th>Description</th><th>Date</th></tr>" +
"<tr><td> </td><td> </td><td> </td></tr>" +
"<tr><td> </td><td> </td><td> </td></tr>" +
"</table>";
// TODO: Do not do .Result! Use await / Task.Wait() in production code!
var response = CreateProject("My project", description).Result;
if (response.ResponseStatus == ResponseStatus.Completed && response.StatusCode == HttpStatusCode.Created)
{
Console.WriteLine(response.Content);
}
else
{
// TODO: Handle error response correctly in production code!
Console.WriteLine($"HTTP status: {response.StatusCode}, " +
$"response status: {response.ResponseStatus}, " +
$"response message: {response.ErrorMessage}");
}
}
}
}