2016-05-31 10 views
2

C#とPHPの間の安定した通信とデータ転送に頼っているアプリケーションに取り組んでいます。C# - PHPの文字エンコーディングの不一致


プラン:私たちは、PHPサーバーへのAPI要求を行うことによって返されます値を編集することができているC#でデスクトップアプリケーションを作成する


問題

例えば特殊文字を含む値を送信:C#RestClientクラスを使用して、PHPにéを、私たちは、PHPに達したときに値が用から変更しまったAPIことが判明例:éé

これについての情報を検索すると、これは文字エンコーディングと関連があり、PHP APIはutf-8を使用し、C#はわかっている限り、utf-8を使用しています。


コード


要求で送信し、作成C#の部分:

string tmp = JsonConvert.SerializeObject(deelname); 
client = new RestClient((local) ? "http://rotserver" : "https://registrations.roundtexel.com/"); 
var request = new RestRequest((local) ? "?action=deelname" : "api/bewerk", Method.POST); 
request.AddParameter("username", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(User)) : User); 
request.AddParameter("type", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes("deelname")) : "deelname"); 
request.AddParameter("inschrijf_id", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(inschrijf_id)) : inschrijf_id); 
request.AddParameter("stuurman_id", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(stuurman_id)) : stuurman_id); 
request.AddParameter("bemanning_id", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(bemanning_id)) : bemanning_id); 
request.AddParameter("voertuig_id", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(voertuig_id)) : voertuig_id); 
request.AddParameter("boot_id", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(boot_id)) : boot_id); 
request.AddParameter("content", (local) ? Convert.ToBase64String(Encoding.UTF8.GetBytes(tmp)) : tmp); 
IRestResponse response = client.Execute(request); 

コードのPHP/API部:

に変更されました:そのため、我々は名前があることを見出した var_dump

、私は誰もがこれで私たちを助けることができることを願っていますAndré

よろしく、 ジェフリー

答えて

0

あなたは文字列をhtmlでエスケープしようとすると、éが&#233に変更されます。または&acacute;あなたがそれを送る前に。 PHP

+0

でC#とがhtml_entity_decodeで

使用HttpUtility.HtmlEncodeあなたはURLエンコードに文字列をエンコードするので、あなたは、PHPでurldecode($文字列)を使用する必要があります –

関連する問題