在Rest API中发布信息的阿拉伯字体问题

时间:2019-07-11 05:14:13

标签: c# rest post

我正在使用以下代码调用post方法。所有工作均正确完成。问题仅在于将驱动程序的名称放在波斯语中。将数据库保存为不必要的字母,例如-EJ / EG1'(J

问题不是数据库和服务器端。因为根据Admin,其他打电话给他们信息的人都是正确的

如果您在此领域有任何经验,感谢朋友的帮助。

我的代码是

private static string Post(string url)
{
    string postData = string.Empty;

    HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url);

    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, postData);

    byte[] data = ms.ToArray();

    httpWReq.ContentLength = data.Length;

    httpWReq.Method = "POST";
    httpWReq.Headers.Set(HttpRequestHeader.AcceptEncoding, "UTF-8");
    httpWReq.Headers.Set(HttpRequestHeader.AcceptCharset, "UTF-8");
    httpWReq.Headers.Set(HttpRequestHeader.AcceptLanguage, "fa-ir, ar, en"); 

    httpWReq.Headers.Add(HttpRequestHeader.AcceptCharset, "UTF-8");
    httpWReq.Headers.Add(HttpRequestHeader.AcceptEncoding, "UTF-8");
    httpWReq.Headers.Add(HttpRequestHeader.AcceptLanguage, "fa-ir, ar, en");

    httpWReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:fa-ir";

    httpWReq.Accept = "application/x-www-form-urlencoded;charset=UTF-8";
    httpWReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
    httpWReq.Headers.Add("USER", "62");
    httpWReq.Headers.Add("PASSID", "11111");
    httpWReq.Headers.Add("DRIVER", "علی محمدی");

    byte[] bytes = Encoding.UTF8.GetBytes(postData.ToString());

    using (Stream newStream = httpWReq.GetRequestStream())
    {
        newStream.Write(data, 0, data.Length);
    }

    HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();

    Stream stream = response.GetResponseStream();

    Encoding encode = System.Text.Encoding.GetEncoding("UTF-8");

    StreamReader streamReader = new StreamReader(stream, encode);

    string html = streamReader.ReadToEnd();

    response.Close();

    streamReader.Close();


    return html;
}

0 个答案:

没有答案