My problem : I want to write datas with a StreamWriter (my String contains letters é and è) but it doesn't work. Without this letters, it works.
The error : Cannot close the stream
My code :
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é (problem with this é)
How can I resolve this problem please ?
Thanks
Set the encoding for the StreamWriter:
Try this, I hope it helps. It worked for me!