Non-ASCII character transfer between two asp.net MVC web applications will not be recognized

I have two asp.net mvc-4 and mvc-5 web applications, now in my first asp.net mvc I have the following WebClientto call the action method (Home / CreateResource) in the 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 the object datathat is passed to the second method of action, it contains a value for the password, and this value is equal in my case ££123, which has 2 non-ASCII characters ..

Now, according to the second method of action, he will take the above value as follows: -

enter image description here

- , , ASCII, ? , , . - , ?

+4
4

:

WebClient, , ASCII ( ASCII), £.

, , , 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);
}

- WebClient, , .

+7

wc.Headers.Add(HttpRequestHeader.ContentType, "application/json"); wc.Headers.Add(HttpRequestHeader.ContentType, "application/json;charset=utf-8");

+2

. UploadDataAsync

using (WebClient client = new WebClient())
{
    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
    client.Headers.Add(HttpRequestHeader.Accept, "application/json");
    client.UploadDataAsync(new Uri(apiUrl), "POST", Encoding.UTF8.GetBytes(jsonString));
}
+1

UTF-8 , ( ), :

64 .

s:

string encoded = Convert.ToBase64String(Encoding.ASCII.GetBytes(s));

encoded:

string s = Encoding.ASCII.GetString(Convert.FromBase64String(encoded));
+1

Source: https://habr.com/ru/post/1649782/


All Articles