c# - Passing non-ASCII characters between two asp.net MVC web applications will not be recognized -


i have 2 asp.net mvc-4 , mvc-5 web applications,, inside first asp.net mvc have following webclient call action method (home/createresource) on second web application :-

using (webclient wc = new webclient())           {           var data = jsonconvert.serializeobject(cr);                        string url = scanningurl + "home/createresource";           uri uri = new uri(url);           wc.headers.add(httprequestheader.contenttype, "application/json");           wc.headers.add("authorization", token);           output = wc.uploadstring(uri, data);          } 

now inside data object being transferred second action method, contain value password , value in case ££123 have 2 non-ascii characters ..

now on second action method accept above value follow:-

enter image description here

so can adivce if there way pass non-ascii characters between 2 action methods ? check on first action method password being serialized , , password being passed correctly view action method. problem somewhere inside how data being transferred inside network or how model binder on second action method accepting incoming data object??

to summarize:

you need specify webclient's encoding property if want transmit non-ascii (or high-ascii) characters such £.

the order in set property values not important in case, provided set before calling uploadstring.

using (webclient wc = new webclient()) {     var data = jsonconvert.serializeobject(cr);     string url = scanningurl + "home/createresource";     uri uri = new uri(url);     wc.headers.add(httprequestheader.contenttype, "application/json");     wc.headers.add("authorization", token);     wc.encoding = encoding.utf8;     output = wc.uploadstring(uri, data); } 

in case wish download data website using webclient, make sure set encoding value used website.


Comments