.Net 核心 api 2.2 请求 Coldfusion Api 插入到 MSSQL 数据库的字符问题

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

我从 .net core api 向 coldfusion api 发出请求,如下所示

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

}

在 coldfusion 中 api 我收到如下请求 json

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

然后,我将 json 数据发送到另一个页面以将数据插入 MSSQL 数据库。

这是我传递数据的方式:

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

在另一个页面中,我使用如下代码。

<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()#">
)

奇怪的是,在插入的时候,formstruct参数变化如下:

我不明白为什么它在插入为 ı,ü 时发生变化。

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

我刚刚添加的唯一内容是 charset=utf-8 到 contentType。让我分享整个代码 .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();
     }