gpt4 book ai didi

c# - UTF8 编码 C# Webrequest

转载 作者:行者123 更新时间:2023-11-30 16:15:33 24 4
gpt4 key购买 nike

我正在尝试发出网络请求并发送希伯来语的帖子数据但服务器端得到它就像“??????”而不是希伯来语。

    WebRequest request = WebRequest.Create(MyserverClient.Url + Constants.TaskUpdatePropertyURL);
((HttpWebRequest)request).AllowAutoRedirect = false;
((HttpWebRequest)request).KeepAlive = true;

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;";
request.Headers.Add("Pragma: no-cache");
request.Headers.Add(string.Format("Cookie: {0}", Client.phpId));
request.Headers.Add(string.Format("requesttoken: {0}", requestToken));

string postData = "Some Non-english text";
using (Stream dataStream = request.GetRequestStream())
{
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}

try{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream2 = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream2);
// Read the content.
responseFromServer = reader.ReadToEnd ();
}
return responseFromServer;

}

正如我所说,对于非英语服务器,服务器获取的帖子数据为“???? -??????????????”但我应该是“一些非英文文本”有什么建议吗??

最佳答案

尝试这样的事情:

StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

关于c# - UTF8 编码 C# Webrequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19475634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com