0

I am new to c# ,Here I am sending a string as a parameter of a API method .

Before that I have converted a password in API as a hashed string to the database .Then I retrieve it from angular 4 and passing again it to API while receiving in Angular 4 I got the same string which I stored in database .

When I pass it to the API ,In API I received the string but it losses + symbols in it .

Specifically it loss all the + in the string .I have tried to replace space with + but it not working in this .

 string cc = mPasswordHash.Replace(" ", "+");

Passed String to API : AhU29yCXdtoaNyQ8rhUBZMz0MieMNBTUaaA04hO+pGzd/iK01sQx6ckMi8LqCdyphShlBt9QhLtCizcUsy708eU90GD7Qg==

Received String :

AhU29yCXdtoaNyQ8rhUBZMz0MieMNBTUaaA04hO(here + is not there)pGzd/iK01sQx6ckMi8LqCdyphShlBt9QhLtCizcUsy708eU90GD7Qg==

can anyone help me to solve this .

Zhu
  • 3,679
  • 14
  • 45
  • 76
  • Try using [encodeURIComponent](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) when sending the value to the API (assuming you are doing this from javascript; are you?) – Peter B Sep 07 '18 at 14:23
  • This should be helpful https://stackoverflow.com/questions/575440/url-encoding-using-c-sharp – Coke Sep 07 '18 at 16:08

1 Answers1

0

If you have control over the request being sent you should encode your URI. This ensures special characters are transported to the destination server in a standardized format. C# has functions built in for encoding and decoding strings as well:

System.Net.WebUtility.UrlEncode

System.Net.WebUtility.UrlDecode

Neil
  • 1,613
  • 1
  • 16
  • 18