Coding issues with C#

৫০০টি ভিউ
প্রথম অপঠিত মেসেজটিতে চলে আসুন

Natalia Dulko

পড়া হয়নি,
৬ অক্টো, ২০১৬, ৯:৩৯:৩০ AM৬/১০/১৬
প্রাপক devtarge...@googlegroups.com,bjo...@gmail.com

I got an interesting thing.

https://lh3.googleusercontent.com/-Psn76iUolJY/V_ZRfb0XnQI/AAAAAAAAATY/jGEIWD3loTMLJE52Ku85uRXsaWsj5GRSQCLcB/s1600/2016-10-06_1627.png

 

 

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

 

tsar...@targetprocess.com

পড়া হয়নি,
৬ অক্টো, ২০১৬, ১১:২২:০৩ AM৬/১০/১৬
প্রাপক DevTargetProcess,bjo...@gmail.com,du...@targetprocess.com
Hello! 

The issue in on your side (encoding?).

Very basic sample for creating project with custom html (using RestSharp) in description is located below.
Result looks like:


Also, ensure your source code page is UTF8 before save (Visual Studio / File / Advanced Save Options...):

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}");
           
}
       
}
   
}
}

Hope, this helps!
সকলকে উত্তর দিন
লেখককে লিখে পাঠান
ফরওয়ার্ড করুন
0টি নতুন মেসেজ