Recently, we were working on Data Interconnection with a company. Our technical staff observed that some of the data could not be verified by MD5 encryption.
OriginalCodeAs follows:
1 [Httppost]
2 Public Actionresult index ( String Lcdata)
3 {
4 String Lcdatadecode = httputility. urldecode (lcdata, encoding. utf8 );
5 String Response = dosometing (lcdatadecode );
6
7 Return Redirecttoaction ( " Index " );
8 }
Through data comparison between the two parties, it is found that the lcdata value in the above Code is a value after the decode, not the original data. Due to this decode, the plus sign "+" in the data is filtered out.
See Dudu'sArticleDistinction and Application of httputility. urlencode, httputility. urldecode, server. urlencode, and server. urldecode
Some solutions have been found on the Internet.Request.Querystring["Key"].Replace("", "+");. However, our data cannot be processed in this way, because the transmitted data contains a space.
Therefore, we found the following method:
1 [Httppost]
2 Public Actionresult index ( String Lcdata)
3 {
4 RegEx r = New RegEx ( @" Lcdata = (? <Value> [^ & =] +) " ); // For our needs, if we need to resolve all (? <Name> [^ & =] +) = (? <Value> [^ & =] +)
5 Match m = R. Match (request. Params. tostring ());
6
7 Lcdata = M. Groups [ 1 ]. Value;
8 String Lcdatadecode = httputility. urldecode (lcdata, encoding. utf8 );
9
10 String Response = dosometing (lcdatadecode );
11
12 Return Redirecttoaction ( " Index " );
13 }
Hope to help other friends in need.