Yesterday afternoon, easy Bao maintenance personnel contact me, ask me three order status, they are deducted the fee is successful, we this is still the order to charge status, after inspection found the signature of the two sides have a problem, carefully see the three orders have a common, user name contains Chinese, then the right remedy ...
Since the ePRO after the successful notice to us, the string with gb2312 UrlEncode, and our interface is implemented with. NET, so the default encoding format is Utf-8, so after receiving the request, the contents of the string Utf-8 UrlDecode, Cause my Side Httputility.urldecode (request["user_name"), encoding.getencoding ("GB2312") obtained data is garbled.
Now the problem to find the reason, how to modify it ...
I looked at the entire request object and found that the parameters obtained in the Request.Url.Query were the most primitive values that were not decoded before the URL and then changed.
1 Public StaticNameValueCollection getquerystring (stringqueryString, Encoding Encoding)2 {3queryString = Querystring.replace ("?","");4NameValueCollection result =NewNameValueCollection (stringcomparer.ordinalignorecase);5 if(!string. IsNullOrEmpty (queryString))6 {7 intCount =querystring.length;8 for(inti =0; I < count; i++)9 {Ten intStartIndex =i; One intindex =-1; A while(I <count) - { - Charitem =Querystring[i]; the if(Item = ='=') - { - if(Index <0) - { +index =i; - } + } A Else if(Item = ='&') at { - Break; - } -i++; - } - stringKey =NULL; in stringValue =NULL; - if(Index >=0) to { +Key = Querystring.substring (StartIndex, index-startIndex); -Value = querystring.substring (index +1, (I-index)-1); the } * Else $ {Panax NotoginsengKey = Querystring.substring (StartIndex, I-startIndex); - } the +Result[key] =Httputility.urldecode (value, encoding); A the if((i = = (Count-1)) && (querystring[i] = ='&')) + { -Result[key] =string. Empty; $ } $ } - } - returnresult; the } - WuyiNameValueCollection col = getquerystring (Request.Url.Query, Encoding.GetEncoding ("GB2312")); the stringuser_id = col["user_name"];
C # URL Auto-decode solution