sql-servercoldfusionhttpwebrequestasp.net-core-2.0coldfusion-10

.Net core api 2.2 request to Coldfusion Api character issue inserting to MSSQL db


I make the request to coldfusion api from .net core api as shown below

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";

var jsonSeri_ = Newtonsoft.Json.JsonConvert.SerializeObject(_frmCustomerTicket);

Encoding iso = Encoding.GetEncoding("iso-8859-9");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(jsonSeri_);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
string msg = iso.GetString(isoBytes);

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{

    streamWriter.Write(msg);

}

in coldfusion api I get the request json as below

<cfif cgi.content_type EQ "application/json">
      <cfset _deserializeJSON = deserializeJSON(ToString(getHTTPRequestData().content))>
    <cfelse>
{"userFname":"","userEmail":"","companyId":1,"priority_id":3,"userLTopic":"donanım arızası","pdesc":"cookie güzel bir şekilde çalışıyorrrrr"}

then, I send the json data to another page to insert the data to MSSQL database.

this is how I pass the data:

 <cfset var formStruct = _deserializeJSON />
 <cfinclude template="queryexecute.cfm">

In another page, I use the code as below.

<cfprocessingdirective pageEncoding="utf-8">

<cfparam name="formStruct" default="">

INSERT INTO
  G_SERVICE
   (
                            
     SERVICE_ACTIVE,
     ISREAD,
     SERVICECAT_ID,
     SERVICE_STATUS_ID,
     PRIORITY_ID,
     COMMETHOD_ID,
     SERVICE_HEAD,
     SERVICE_DETAI
 )
 VALUES
  ( 
    1
    , 0
    , 1
    , 92
    , #formStruct.priority_id#
    , 0
    , <cfqueryparam cfsqltype="CF_SQL_NVARCHAR" value="#(formStruct.userLTopic)#">
    , <cfqueryparam cfsqltype="CF_SQL_NVARCHAR" value="<p>  #(formStruct.pdesc)#  </p>">
    , <cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#now()#">
    , <cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#now()#">
)

The weird thing is that, when it is being inserted, the formstruct parameters changes as below:

I can not get why it changes while being inserted as ı,ü .

{"userFname":"","userEmail":"","companyId":1,"priority_id":3,"userLTopic":"donanım arızası","pdesc":"cookie güzel bir şekilde çalışıyorrrrr"}

Solution

  • the only thing I have just added is charset=utf-8 to contentType. Let me share the whole code .net core web api 2.0

    request.ContentType = "application/json; charset=utf-8";

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://url");
                
      request.ContentType = "application/json; charset=utf-8";
      request.Method = "POST";
    
       using (var streamWriter = new StreamWriter(request.GetRequestStream()))
       {
           string json2 = JsonConvert.SerializeObject(_frmCustomerTicket);
           streamWriter.Write(json2);
        }
    
       HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       var result = "";
       using (StreamReader reader = new StreamReader(response.GetResponseStream()))
         {
                    result = reader.ReadToEnd();
         }