我的问题:我想用StreamWriter写入数据(我的String包含字母é和è),但是它不起作用。没有这封信,它就可以工作。

错误:无法关闭流

我的代码:

 string postString = "id=" + sIdTransaction + "&nom=" + sNom + "&prenom=" + sPrenom + "&email=" + sEmail + "&adresse.rue=" + sRue + "&adresse.codePostal=" + sCodePostal + "&adresse.ville=" + sVille;
string sIdContractant = "";
Encoding iso = Encoding.GetEncoding("utf-8");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(postString);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
postString = iso.GetString(isoBytes);

string sUrlAuth = "https://test.contralia.fr/Contralia/api/transactions/" + sIdTransaction + "/contractant/";
HttpWebRequest webRequest = CreationRequete(sUrlAuth);
webRequest.ContentLength = postString.Length;


StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();

adresse.Ville =Fercé(此é的问题)
请问该如何解决?谢谢

最佳答案

设置StreamWriter的编码:

StreamWriter sw = new StreamWriter(webRequest.GetRequestStream(), encoding)

试试这个,希望对您有所帮助。它为我工作!

关于c# - 如何用StreamWriter编写特殊字符(é,è)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17832502/

10-11 22:26
查看更多