How can I encode this query string?

I am trying to implement a payment processor. To verify that the answer is legal, I have to take a query string and add a validation key, then execute an MD5 hash and match my hashed values ​​to theirs.

The payment processor generates its hash based on the request:

trnId = 10000041
& amp ; MessageText = Duplicated + deal +% 2D + This + deal + else + already + were + approved
& amp; trnAmount = 11.20
& amp; trnDate = 6% 2F8% 2F2011 + 12% 3A32% 3A20 + PM
& amp; trnEmailAddress = John% 2Edoe% 40gmail% 2Ecom
& Amp; avsMessage = Address + Verification + + does not work + for + it + transactions% 2E
& ref1 = aab02ccd% 2D7d17% 2D4d09% 2Da30c% 2Dad6324fe33f1

Now, if I called QueryString["messageText"], I would receive "Duplicate Transaction - This transaction has already been approved". I can’t use this because I need +and%2D

So, to generate my string, I am doing something like this:

NameValueCollection queryString = new NameValueCollection(QueryString);
queryString.Remove("hashValue");

List<string> parameters = new List<string>();
foreach(string qs in queryString.Keys)
   parameters.Add(qs + "=" + HttpUtility.UrlEncode(QueryString[qs]));

string value = string.Join("&", parameters.ToArray());

My summary line:

trnId = 10000041
& amp ; MessageText = Duplicated + deal + - + + This deal + has + already + been + approved +
& amp; trnAmount = 11.20
& amp; trnDate = 6% 2F8% 2f2011 + 1% 3a05% 3a09 + PM
& amp; trnEmailAddress = john.doe% 40gmail.com
& amp ; avsMessage = Address + verification + not + running + for + this + transaction
. & ref1 = aab02ccd-7d17-4d09-a30c-ad6324fe33f1

, , . %2f %2f.

, string.replace? , , , ?

+3
2

QueryString.ToString(), , &, + .. , Request.RawUrl.Split('?')[1].

+1

Rick Strahl : Html Uri String Encoding System.Web

, System.Web - , , ( ).

, , , string.Replace() string.ToUpper() - , .

+1

All Articles